I work on a project, made with Spring Framework, where i want to use JaxB, to convert an object to json, and i recieve this error:
javax.xml.bind.PropertyException: name: eclipselink.media-type value: application/json
at javax.xml.bind.helpers.AbstractMarshallerImpl.setProperty(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.setProperty(Unknown Source)
at com.fabbydesign.controller.DashboardController.main(DashboardController.java:82)
The code that i test is:
public static void main(String[] args) throws ParseException{
ReturnBean rb = new ReturnBean();
rb.setStatus(1);
rb.setMessage("Message here!");
JAXBContext jc;
try {
jc = JAXBContext.newInstance(ReturnBean.class);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
marshaller.marshal(rb, System.out);
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I have added in pom.xml EclipseLink dependency:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.4</version>
</dependency>
and, i have added the file jaxb.properties
with the content:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
I don't know why i still recieve this error, because, as i read on this forum i think i did all. What i want to mention, is, that the code that i test is in the directory:
src\main\java\com\fabbydesign\controller
and the file jaxb.properties
is in the directory:
src\main\resources\com\fabbydesign\controller
What I did wrong?