Je voudrais savoir s'il existe une page Web/un logiciel capable de «traduire» un objet de flux JSON en un objet Java avec des attributs.Flux JSON vers Java Objet
Par exemple:
{
'firstName': 'John',
'lastName': 'Smith',
'address': {
'streetAddress': '21 2nd Street',
'city': 'New York'
}
}
deviendrait:
class Person {
private String firstName;
private String lastName;
private Address address;
public String getFirstName() { return firstName; }
public String getLastName() { return lastName; }
public Address getAddress() { return address; }
public void setFirstName(String firstName) { this.firstName = firstName; }
public void setLastName(String lastName) { this.lastName = lastName; }
public void setAddress(Address address) { this.address = address; }
public String toString() {
return String.format("firstName: %s, lastName: %s, address: [%s]", firstName, lastName, address);
}
}
class Address {
private String streetAddress;
private String city;
public String getStreetAddress() { return streetAddress; }
public String getCity() { return city; }
public void setStreetAddress(String streetAddress) { this.streetAddress = streetAddress; }
public void setCity(String city) { this.city = city; }
public String toString() {
return String.format("streetAddress: %s, city: %s", streetAddress, city);
}
}
Je ne demande pas que parce que je suis paresseux, mais le JSON je voudrais analyser a beaucoup d'attributs .