Is there any plain way
- to print a JAXB annotated instance
- in JSON format (as exactly jersey will print in AS)
- while running unit testing
- without any embedded server launched?
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:
You can use an
StringWriter
to take theString
representation of the marshalled JSON output.