线程“main”中的异常javax.xml.bind.PropertyException:name:eclipselink.media-type value:application / json [英] Exception in thread "main" javax.xml.bind.PropertyException: name: eclipselink.media-type value: application/json

查看:148
本文介绍了线程“main”中的异常javax.xml.bind.PropertyException:name:eclipselink.media-type value:application / json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照

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(MarshallerProperties.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 javax.xml.bind.helpers.AbstractMarshallerImpl.setProperty(AbstractMarshallerImpl.java:358)
   at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.setProperty(MarshallerImpl.java:527)
   at HelloWorld.main(HelloWorld.java:17)

This is what I'm doing,

解决方案

You need to have the EclipseLink jars (2.4.0 or newer) on your class path, and a jaxb.properties file in the same package as the classes used to bootstrap theJAXBContext with the following entry:

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

Below is a link to an example on GitHub that you can run to see everything working:

这篇关于线程“main”中的异常javax.xml.bind.PropertyException:name:eclipselink.media-type value:application / json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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