Is there an easy way
- to print an annotated JAXB instance
- in JSON format (since it is Jersey that will print to AS)
- when testing modules
- without starting the embedded server?
I can run and see in XML using JAXBContext, Marshaller, etc.
Is there any example for JSON?
I found him. This is 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>
source
share