I am trying to generate rest service using Apache CXF and Jackson data-binding. here I don't want to use @XmlRootElement annotation. when I try below code the request object coming like a null object.
here is my service interface
@POST
@Path("/getusers/")
@Consumes("application/json")
@Produces("application/json")
public List<UserDetails> getusers(UserDetails userDetails) throws ServiceException;
here is my domain object
public class UserDetails implements Serializable{
private String userName;
private int userId;
public UserDetails(){
}
//getters and setters...
}
The Json Object looks like
{
"id" : "102",
"username" : "scott"
}
And I am getting null-pointer exception for the request object
how do I access my request object Note: here I am using Jackson Data-Binding
Your JSON contains username
while the member is called userName
. Also, id
and userId
are different.
You have three options:
UserDetails
members to match the fields in the JSON object. UserDetails
. @JsonProperty
to configure the JSON object name to be bound to a UserDetails
member.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.