0

ERROR MESSAGE

org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "address" (Class entity.User), not marked as ignorable
 at [Source: org.apache.catalina.connector.CoyoteInputStream@1c6a59e0; line: 1, column: 67] (through reference chain: entity.User["address"])

HTML

<input type="text" class="" id="address" name="address" placeholder="Street"/>
<input type="text" id="postalCode" name="postalCode" placeholder="Zipcode"/></br>
<input type="text" id="city" class="" name="city" placeholder="City"/>
<input type="text" id="country" name="country" placeholder="Country"/>

Address object got a field City and zip code

private String address;
private City cityId;
private String postalCode;

City-object includes Country

private Country countryId;

Java Script

return JSON.stringify({
      "address": $('#address').val(),
      "postalCode": $('#postalCode').val(),
      "city": $('#city').val()
   });
$.ajax({
   type: "POST",
   contentType: "application/json",
   url: "http://localhost:8080/testSoft/webresources/entity.user/",
   dataType: "json",
   data: formToJSON(),
   success: function(response)

User-object

@Entity

@Table(name = "users")
@XmlRootElement
public class User implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "username")
    private String username;
...
    @JoinColumn(name = "address_address_id", referencedColumnName = "address_id")
    @ManyToOne
    private Address addressAddressId;

QUESTION

How can I handle the nested objects when posting json-objects to my web service? In my case Address is an object in User-object, City is an Object and there is Country-object in City-object.

Sami
  • 2,311
  • 13
  • 46
  • 80
  • Can you show your User object? – Rohit Feb 17 '13 at 03:43
  • Done, I added User object and its Address field. – Sami Feb 17 '13 at 13:50
  • Refer to these other related posts in case you have'nt http://stackoverflow.com/questions/4486787/jackson-json-unrecognized-field-not-marked-as-ignorable http://stackoverflow.com/questions/6300311/java-jackson-org-codehaus-jackson-map-exc-unrecognizedpropertyexception – Rohit Feb 17 '13 at 16:05
  • I don't want to ignore them, I would like to use city and country fields and when user is signing up the address goes to correct place etc. Now I have no idea how to do that. – Sami Feb 17 '13 at 16:26
  • I think what you are trying to do is map your address fields (address,postal,code city) to your User object instead of Address inside the user .Can you do something like (corretc it as needed) url: "http://localhost:8080/testSoft/webresources/entity.user.address/" – Rohit Feb 17 '13 at 16:43
  • I just try to map address, postal code, city and country from the UI to their objects in server, but they are inside of the user. User---Address---City---Country etc. Is there even way to do that or should I read request parameters and populate the objects by hand? – Sami Feb 17 '13 at 17:40

0 Answers0