Converting Java Object to Json using Marshaller
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Its quite easy to convert a java object to XML by using Marshaller. But I need to convert a java object to JSON by using marshaller alone. I know its good to use gson or Xstream like things., but I need to do using Marshaller.How to achieve it? Thanks in advance. 回答1: Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group, Below is how this can be done if you are using MOXy as your JAXB provider. http://blog.bdoughan.com/2011/08/json-binding-with-eclipselink-moxy.html JAVA MODEL Customer import java.util.*