I have created a simple REST service with two resources. The first resource works great and just returns MediaType.TEXT_PLAIN.
For the second resource I wanted to try mapping POJO to Java and followed this example:
https://github.com/jersey/jersey/tree/2.3.1/examples/json-moxy/src/main/java/org/glassfish/jersey/examples/jsonmoxy
with my testbean defined as:
@XmlRootElement
public class Company {
public String name;
public String symbol;
public String country;
public Company(String name, String symbol,
String country) {
this.name = name;
this.symbol = symbol;
this.country = country;
}
public String getName() {
return name;
}
public String getSymbol() {
return symbol;
}
public String getCountry() {
return country;
}
}
The resource is trivial as well:
@Path("company/{name}")
public class CompanyResource {
private Map<String, Company> companies;
public CompanyResource() {
companies = new LinkedHashMap<String, Company>();
companies.put("Apple", new Company("Apple Inc.", "AAPL", "USA"));
companies.put("Microsoft", new Company("Microsoft Corp.", "MSFT", "USA"));
companies.put("Honda", new Company("Honda Motor Co Ltd", "HMC", "Japan"));
companies.put("Random", new Company("Random Inc.", "RND", "Undefined"));
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public Company getCompany(@PathParam("name") String name) {
Company cmp = companies.get(name);
if (cmp == null) {
return companies.get("Random");
}
return cmp;
}
}
I have debugged a request and arrive at the return statement without problems. From here however, I think a JAXBException is thrown but I am unable to view the details, and nothing appears in any log anywhere. All that happens is that the browser display an "internal server error 500" message.
Under monitoring configuration I have in desperation set everything to level HIGH. Still nothing appears anywhere.
The only similar questions I found were jax-rs 2.0 and Glassfish 4 unable to @consume JSON into Pojo and JAX RS Jersey + JSON --> HTTP 500 Internal Server Error but they didn't seem entirely related.
For client I am simply using Google Chrome with the "Advanced REST Client" app.
Any help would be much appreciated.
See Question&Answers more detail:
os