4

I'm attempting to follow the example located here but get an javax.xml.bind.PropertyException. I receive this exception because of the following line of code:

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

I have literally copy/pasted the example listed above so my code is exactly what you see there. Searching SO and Google for this has not been helpful, and thought I'd bring this to the geniuses at SO for some help. Any help would be most appreciated, (de)serialization with JSON and XML with json.org, Jackson, and JAXB has turned into a black and bottomless pit that has consumed almost a month of my life.

My first impression was that I wasn't properly specifying the eclipselink runtime (as described here) but that didn't produce 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

Community
  • 1
  • 1
Prmths
  • 2,022
  • 4
  • 21
  • 38

1 Answers1

4

You need be sure you are using EclipseLink 2.4.0 or above. The current version is 2.5.0 which can be downloaded at (or obtained from Maven Central):


UPDATE

MOXy also offers the following convenience classes to access the extension properties:

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

This means you could do the following:

marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • 1
    Blaise, thank you for that. Two days ago, I somehow downloaded 2.5 and deleted it thinking I'd actually updated it and didn't check in eclipse where it was clearly labeled 2.2. This did resolve my problem. – Prmths Aug 29 '13 at 00:09
  • 1
    IMHO this is a horrible design flaw of JAXB. I keep getting error like this because there is no direct programmatic control over the JAXBContextFactory in use - e.g. no version check. I am avoiding JAXB now more often than not just for this reason. – Wolfgang Fahl Jun 23 '15 at 07:07
  • I'm still seeing this error with a custom provider in Jersey 2.18 (though the default provider works fine). Confirmed org.eclipse.persistence.moxy, .core, and .asm are at 2.6, and even tried forcing a dependency to the entire eclipselink to 2.6 with no luck. I'm using the convenience classes, still error. Anyone have any ideas? – cacois Aug 11 '15 at 13:36