I am passing json string from restclient to resteasy webservice for model object user.
I have set Content-Type=application/json
and my json string in body is as follows,
{
"id": "100",
"email": "email",
"add": [
{
"lastName": "lastName",
"firstName": "firstName"
},
{
"firstName": "firstName",
"lastName": "lastName"
}
]
}
If i remove add array object as below, then i am getting the response as expected.
{
"id": "100",
"email": "email",
}
When i try to send add array , server is throwing an exception saying,
Caused by: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of com.model.add out of START_ARRAY token
I tried this way also, but its not working,
{
"id": "100",
"email": "email",
"lastName": "Something Four",
"firstName": "Something Five"
}
Then it is giving below error,
Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "lastName" (Class com.model.user), not marked as ignorable
My model objects are below,
public class user implements Serializable {
@Id
@Column(name="Id", unique=true, nullable=false)
private int id;
@Column(name="email", nullable=true, length=60)
private String email;
@ManyToOne(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="Id", nullable=false)
private add add;
}
public class add implements Serializable {
@Id
@Column(name="Id", unique=true, nullable=false)
private String id;
@Column(name="LastName", nullable=true, length=128)
private String lastName;
@Column(name="FirstName", nullable=true, length=128)
private String firstName;
}
My service class
@POST
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response addAccount(@FormParam("id") String id,
@FormParam("lastName") String lastName,
@FormParam("firstName") String firstName,
@FormParam("email") String email{
user.setId(id);
add.setLastName(lastName);
add.setFirstName(firstName);
user.setEmailAddress(email);
}
Can anyone help me in passing one model object inside other model object as an array in json string?