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

4

1 回答 1

4

您需要确定您使用的是 EclipseLink 2.4.0 或更高版本。当前版本是 2.5.0,可以在(或从 Maven Central 获得)下载:


更新

MOXy 还提供以下便利类来访问扩展属性:

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

这意味着您可以执行以下操作:

marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
于 2013-08-28T23:43:37.760 回答