简体   繁体   中英

how to get request object without using @XmlRootElement for java objects in rest services

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:

  • Change the names of the UserDetails members to match the fields in the JSON object.
  • Change the names of the JSON object to match the member names of UserDetails .
  • Use @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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM