Ich arbeite an einem Projekt mit Spring Framework, wo ich JaxB verwenden möchte, um ein Objekt in JSON zu konvertieren, und ich empfangen diesen Fehler:javax.xml.bind.PropertyException: name: eclipselink.media-typ Wert: application/json
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)
Der Code, den ich testen:
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();
}
}
ich in pom.xml Eclipse Abhängigkeit hinzugefügt haben:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.4</version>
</dependency>
und ich habe die Datei jaxb.properties
mit dem Inhalt hinzugefügt:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
Ich weiß nicht, warum ich immer noch diesen Fehler empfangen, weil, wie ich auf diesem Forum zu lesen Ich glaube, ich alle tat. Was ich erwähnen möchte, ist, dass der Code, ich teste im Verzeichnis:
src\main\java\com\fabbydesign\controller
und die Datei jaxb.properties
ist im Verzeichnis:
src\main\resources\com\fabbydesign\controller
Was ich falsch gemacht?
von dort verstehe ich nicht, was ich falsch gemacht habe ?! – fabby