我正在将 json 字符串从 restclient 传递给模型对象用户的 resteasy webservice。
我设置了 Content-Type=application/json
我在正文中的json字符串如下,
{
"id": "100",
"email": "email",
"add": [
{
"lastName": "lastName",
"firstName": "firstName"
},
{
"firstName": "firstName",
"lastName": "lastName"
}
]
}
如果我如下删除添加数组对象,那么我将得到预期的响应。
{
"id": "100",
"email": "email",
}
当我尝试发送 add array 时,服务器抛出异常说,
Caused by: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of com.model.add out of START_ARRAY token
我也试过这种方法,但它不起作用,
{
"id": "100",
"email": "email",
"lastName": "Something Four",
"firstName": "Something Five"
}
然后它给出以下错误,
Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "lastName" (Class com.model.user), not marked as ignorable
我的模型对象如下,
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;
}
我的服务等级
@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);
}
任何人都可以帮助我将一个模型对象作为 json 字符串中的数组传递到另一个模型对象中吗?