JSON feed to Java Object
Posted
by mnml
on Stack Overflow
See other posts from Stack Overflow
or by mnml
Published on 2010-03-13T10:39:33Z
Indexed on
2010/03/13
10:45 UTC
Read the original article
Hit count: 294
Hi, I would like to know if there is a webpage/software that can "translate" a Json feed object to a Java object with attributes.
For example :
{
'firstName': 'John',
'lastName': 'Smith',
'address': {
'streetAddress': '21 2nd Street',
'city': 'New York'
}
}
Would become:
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);
}
}
I'm not asking that because I'm lazy, but the JSON I would like to parse has quite a lot of attribute.
© Stack Overflow or respective owner