使用eclipselink.media-type值设置Marshaller属性时的PropertyException:application / json [英] PropertyException when setting Marshaller property with eclipselink.media-type value: application/json

查看:625
本文介绍了使用eclipselink.media-type值设置Marshaller属性时的PropertyException:application / json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照此处但获取javax.xml.bind.PropertyException。由于以下代码行,我收到此异常:

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");

我已经完全复制/粘贴了上面列出的示例,因此我的代码正是您在那里看到的。搜索SO和谷歌对此没什么帮助,并且认为我会把这些带给SO的天才以获得一些帮助。任何帮助都是最受欢迎的,(de)使用JSON和XML与json.org,Jackson和JAXB进行序列化已经变成了一个消耗了近一个月生命的黑色和无底洞。

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.

我的第一印象是我没有正确指定eclipselink运行时(如此处所述)但是没有产生解决方案。

My first impression was that I wasn't properly specifying the eclipselink runtime (as described here) but that didn't produce a solution.

Stacktrace:

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

推荐答案

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

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):

  • http://www.eclipse.org/eclipselink/downloads/

更新

MOXy还提供以下便利课程访问扩展属性:

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

  • 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");

这篇关于使用eclipselink.media-type值设置Marshaller属性时的PropertyException:application / json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆