I have a web service on Glassfish 4.1 that is working properly for XML but not for JSON.
The entity class is:
@XmlRootElement
public class Person implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8969081094076790550L;
Integer id;
String firstName;
String lastName;
String employeeId;
/**
*
*/
public Person() {
}
@Override
public String toString() {
return firstName + " " + lastName + " [" + employeeId + "] [id: " + id + "]";
}
/**
* @return the firstName
*/
public String getFirstName() {
return this.firstName;
}
/**
* @param firstName the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @return the lastName
*/
public String getLastName() {
return this.lastName;
}
/**
* @param lastName the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @return the employeeId
*/
public String getEmployeeId() {
return this.employeeId;
}
/**
* @param employeeId the employeeId to set
*/
public void setEmployeeId(String employeeId) {
this.employeeId = employeeId;
}
/**
* @return the id
*/
public Integer getId() {
return this.id;
}
/**
* @param id the id to set
*/
public void setId(Integer id) {
this.id = id;
}
}
The relevant service code is:
@GET
@Path("xml")
@Produces(MediaType.TEXT_XML)
public Collection<Person> getPeopleXML() {
return personDao.getAllPeople();
}
@GET
@Path("json")
@Produces(MediaType.APPLICATION_JSON)
public Collection<Person> getPeopleJSON() {
return personDao.getAllPeople();
}
The XML call works, and I get:
<people>
<person>
<employeeId>2234</employeeId>
<firstName>Mike</firstName>
<id>2</id>
<lastName>Jones</lastName>
</person>
<person>
<employeeId>22314</employeeId>
<firstName>Joe</firstName>
<id>4</id>
<lastName>Smith</lastName>
</person>
</people>
I get an error with the JSON call:
HTTP Status 500 - Internal Server Error
type Exception report
messageInternal Server Error
descriptionThe server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: com/fasterxml/jackson/module/jaxb/JaxbAnnotationIntrospector root cause
org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: com/fasterxml/jackson/module/jaxb/JaxbAnnotationIntrospector root cause
java.lang.NoClassDefFoundError: com/fasterxml/jackson/module/jaxb/JaxbAnnotationIntrospector root cause
java.lang.ClassNotFoundException: com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector not found by com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider [129] note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1 logs.
Why the error? I have everything I need, I think. I have an ivy file and tried adding all kinds of jackson deps, but nothing seems to work. I cannot tell if I am having version problems when I add jackson to my ivy file since it's included with Glassfish, or what.
Glassfish provides the following:
/d/glassfish4/glassfish/modules/jackson-annotations.jar
/d/glassfish4/glassfish/modules/jackson-core.jar
/d/glassfish4/glassfish/modules/jackson-databind.jar
/d/glassfish4/glassfish/modules/jackson-jaxrs-base.jar
/d/glassfish4/glassfish/modules/jackson-jaxrs-json-provider.jar
/d/glassfish4/glassfish/modules/jersey-media-json-jackson.jar