PropertyException property when setting the Marshaller property with the value eclipselink.media-type: application / json

I am trying to follow the example here , but getting a javax.xml.bind.PropertyException. I get this exception due to the following line of code:

marshaller.setProperty("eclipselink.media-type", "application/json"); 

I literally copied / pasted the above example, so my code is exactly what you see there. Finding SO and Google did not help for this, and I thought I would bring this genius to SO for some help. Any help would be most appreciated, (de) serialization with JSON and XML from json.org, Jackson and JAXB turned into a black and bottomless pit that consumed almost a month of my life.

My first impression was that I did not correctly specify eclipselink runtime (as described here) , but that did not create a solution,

Stacktrace:

 Exception in thread "main" javax.xml.bind.PropertyException: name: eclipselink.media-type value: application/json at org.eclipse.persistence.jaxb.JAXBMarshaller.setProperty(JAXBMarshaller.java:528) at com.dualoutput.DualOutput.main(DualOutput.java:20) 

Sscce

+4
source share
1 answer

You must be sure to use EclipseLink 2.4.0 or higher. The current version is 2.5.0, which can be downloaded (or obtained from Maven Central):


UPDATE

MOXy also offers the following convenience classes for accessing extension properties:

  • org.eclipse.persistence.jaxb.JAXBContextProperties
  • org.eclipse.persistence.jaxb.MarshllerProperties
  • org.eclipse.persistence.jaxb.UnmarshallerProperties

This means that you can do the following:

 marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json"); 
+4
source

All Articles