rendering JSON String as JSON Using JAXB within jersey

By : epeleg
Source: Stackoverflow.com
Question!

Given a class like this:

@XmlRootElement
public class MyClass {
    private Boolean flag1;
    private String json;
    ...
}

Can I add an annotation that will cause the JSON to become part of the rendered JSON without being escaped as a string?

For example, if the object has flag1=true and json="{"a":5}" I want to get:

{"flag":true,"json":{"a":5}}

instead of:

{"flag":true,"json":"{\"a\":5}"}
By : epeleg


Answers

You can write your own marshaller to do so.

By : Amareswar


You can use a Provider to change default behaviour of JSONJAXBContext. See http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e865

import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException; 

import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.api.json.JSONJAXBContext;

@Provider
public class CustomWoodwingOutputJSONContextProvider implements ContextResolver
By : dometec


This video can help you solving your question :)
By: admin