首页 > 解决方案 > How to Covert a @XmlType to Json string?

问题描述

I want to convert a an entity which is @XmlType to a Json string in java. I searched for such question but all I have found is to convert a XML string to Json string .

标签: javajsonxmlxmltype

解决方案


I would recommend to use the Jackson library for this job. This works with any Java class as long it's structure is somehow compatible to JSON:

ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = ow.writeValueAsString(object);

The "withDefaultPrettyPrinter" part is optional.


推荐阅读