Is there any plain way
I can run and see in XML with JAXBContext, Marshaller, and so on.
Is there any example for JSON?
I found it. It's similar to JAXB.
With Jersey API
final JSONJAXBContext context = new JSONJAXBContext(...);
final JSONMarshaller marshaller = context.createJSONMarshaller();
marshaller.marshallToJSON(...);
final JSONUnmarshaller unmarshaller = context.createJSONUnmarshaller();
final T unmarshalled = unmarshaller.unmarshalJAXBElementFromJSON(
..., T.class).getValue();
for Maven
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<scope>test</scope>
</dependency>
It is possible:
...
StringWriter writer = new StringWriter();
marshaller.marshallToJSON(objectToMarshall, writer)
logger.debug(writer.toString());
...
You can use an StringWriter
to take the String
representation of the marshalled JSON output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With