RestEasy Jettison/Jackson customization
d1x Oct 3, 2012 8:11 AMI'm trying to use my objects with JAXB annotations for application/json output with my JAX-RS resource. I'm running on JBoss AS7 7.1.1.Final with RestEasy (included within AS). The issue is that I would like to customize my JSON output. I must note that I don't care if I will use Jettison or Jackson, but I was able only make Jettison work (deploy application) without errors. I also would like to stick only with JAXB annotations on my objects if possible.
1) I want to omit "@" within XmlAttribute annotated fields. I found out property how to do it with Jettison, but I don't know how to configure it on JBoss AS7. Didn't find any working ContextResolver or any other example.
2) I would like to have "normal" JSON arrays, e.g.
@XmlRootElement(name = "root") @XmlAccessorType(XmlAccessType.FIELD) public class Root { @XmlElementRef(type = Entry.class, required = false) // no difference with @XmlElement private Set<Entry> entries; }
serializes into
{"entries": {"entry":[{...},{...},{...}]} }
and I would expect one of those:
{"entries": [ {"entry":{...}}, {"entry":{...}}, {"entry":{...}} ] }
or (omitting XmlRootElement)
{"entries": [{...}, {...}]] }
3) As I noted, I don't care what provider (Jettison/Jackson) will I use but it is hard to find working example how to correctly set maven dependencies for application to be deployable without errors. So far I'm using:
<dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jaxrs</artifactId> <version>${resteasyVersion}</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jaxb-provider</artifactId> <version>${resteasyVersion}</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jettison-provider</artifactId> <version>${resteasyVersion}</version> <!--<scope>provided</scope>--> <exclusions> <exclusion> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> </exclusion> <exclusion> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> </exclusion> <exclusion> <groupId>javax.xml.stream</groupId> <artifactId>stax-api</artifactId> </exclusion> </exclusions> </dependency>
Thanks for all answers