In my JAX-RS project (Jersey) I'm having a problem getting one of the JAXB-annotated objects marshalled to JSON. Here is the error message I see in the logs:
SEVERE: Internal server error javax.ws.rs.WebApplicationException: javax.xml.bind.JAXBException: class com.dnb.applications.webservice.mobile.view.CompaniesAndLocations nor any of its super class is known to this context.
Does this point to any specific problem? My resource has a method like this:
@Path("/name/{companyname}/location/{location}")
@Produces("application/json; charset=UTF-8;")
@Consumes("application/json")
@POST
public Viewable findCompanyByCompanyNameAndLocationAsJSON(@PathParam("companyname") String companyName,
@PathParam("location") String location, CriteriaView criteria) {
criteria = criteria != null ? criteria : new CriteriaView();
criteria.getKeywords().setCompanyName(companyName);
return getCompanyListsHandler().listsByCompanyNameAndLocation(criteria, location);
}
Viewable is an empty interface. The above method returns an object of type CompaniesAndLocations, defined as follows:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "companiesAndLocations", propOrder = { "count", "normalizedLocations", "companyList", "companyMap", "modifiers",
"modifiersMap", "companyCount", "navigators" })
public class CompaniesAndLocations extends BaseCompanies implements Viewable {
@XmlElement(name = "normalizedLocations", required = false)
protected List<NormalizedLocation> normalizedLocations;
public List<NormalizedLocation> getNormalizedLocations() {
if (normalizedLocations == null) {
normalizedLocations = new ArrayList<NormalizedLocation>();
}
return normalizedLocations;
}
}
BaseCompanies defines a number of other fields:
@XmlTransient
public abstract class BaseCompanies {
@XmlElement(name = "modifiers", required = false)
private List<Modifiers> modifiers;
....
I should add that I'm deviating slightly from the approach used by other working code in the app. The other resource methods get their objects from an ObjectFactory that is annotated with @XmlRegistry. I don't think this is necessary, though. I have seen other code that directly instantiates the JAXB-annotated POJO'swithout using the ObjectFactory factory.
Any ideas?