I am trying to implement JAX-RS service using Jersey and GSON as the JSON provider. The provider is similar to what is outlined in https://gist.github.com/hstaudacher/4967804. My entity class looks as follows:
public class Company implements Serializable{
public static final String DEFAULT_COMPANY = "DEFAULT_COMPANY";
@Expose
@SerializedName("company_id")
private String mcompanyId;
private ConcurrentHashMap<String, User> m_userMap = new ConcurrentHashMap<String, User>();
private ConcurrentHashMap<String, ServiceProvider> m_spMap = new ConcurrentHashMap<String, ServiceProvider>();
private static ConcurrentHashMap<String, Company> s_companyMap = new ConcurrentHashMap<String, Company>();
public Company() {
super();
// TODO Auto-generated constructor stub
}
... additional code omitted for brevity
The corresponding JAX-RS service handler is
@Path("/company")
public class CompanyService {
@GET
@Produces(MediaType.APPLICATION_JSON)
public ArrayList<Company> getCompany() {
return Company.getAll();
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public ArrayList<Company> addCompany(Company c){
System.out.print("Company id ==> " + c.getCompanyId());
Company.getInstance(c.getCompanyId());
return Company.getAll();
}
}
When I invoke this with the following JSON payload
{
"company_id":"test123"
}
It fails. When I look at the logs I see that c.getCompanyId() returns as NULL.
Any ideas as to what I am missing here ?