User Tools

Site Tools


java:restlet:jackson

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
java:restlet:jackson [2018/08/01 09:32]
els created
java:restlet:jackson [2018/08/01 09:52]
els
Line 1: Line 1:
-Using jackson in Restlet is quite simple but has some pitfalls.+Using jackson in Restlet ​(jaxrs) ​is quite simple but has some pitfalls. 
 + 
 +I was using following constellations:​ 
 +====== Maven dependencies ====== 
 +<​Code:​xml>​ 
 +        <​dependency>​ 
 +            <​groupId>​org.restlet.jse</​groupId>​ 
 +            <​artifactId>​org.restlet</​artifactId>​ 
 +            <​version>​3.0-M1</​version>​ 
 +        </​dependency>​ 
 +        <​dependency>​ 
 +            <​groupId>​org.restlet.jse</​groupId>​ 
 +            <​artifactId>​org.restlet.ext.json</​artifactId>​ 
 +            <​version>​3.0-M1</​version>​ 
 +        </​dependency>​ 
 +        <​dependency>​ 
 +            <​groupId>​org.restlet.jse</​groupId>​ 
 +            <​artifactId>​org.restlet.ext.jaxrs</​artifactId>​ 
 +            <​version>​3.0-M1</​version>​ 
 +            <​exclusions>​ 
 +                <​exclusion>​ 
 +                    <​artifactId>​stax-api</​artifactId>​ 
 +                    <​groupId>​javax.xml.stream</​groupId>​ 
 +                </​exclusion>​ 
 +            </​exclusions>​ 
 +        </​dependency>​ 
 +        <!-- Must be before org.restlet.ext.jackson!!!! --> 
 +        <​dependency>​ 
 +            <​groupId>​com.fasterxml.jackson.core</​groupId>​ 
 +            <​artifactId>​jackson-databind</​artifactId>​ 
 +            <​version>​2.9.6</​version>​ 
 +        </​dependency>​ 
 +        <​dependency>​ 
 +            <​groupId>​org.restlet.jse</​groupId>​ 
 +            <​artifactId>​org.restlet.ext.jackson</​artifactId>​ 
 +            <​version>​3.0-M1</​version>​ 
 +            <​exclusions>​ 
 +                <​exclusion>​ 
 +                    <​artifactId>​stax-api</​artifactId>​ 
 +                    <​groupId>​javax.xml.stream</​groupId>​ 
 +                </​exclusion>​ 
 +            </​exclusions>​ 
 +        </​dependency>​ 
 +</​Code>​ 
 + 
 +====== Service ====== 
 +<​Code:​java>​ 
 +    @Path("​rest/​inout"​) 
 +    @POST 
 +    @Produces(MediaType.APPLICATION_JSON) 
 +    @Consumes(MediaType.APPLICATION_JSON) 
 +    public MyOutputType inout(MyInputType input) { 
 +        // Do some Stuff 
 +        return result; 
 +    } 
 +</​Code>​ 
 + 
 +====== MyInput/​OutputType ====== 
 +It is very important to use bean classes to get default BeanSerializer of jackson. 
 + 
 +====== module-info.java ====== 
 +<​Code:​java>​ 
 +    requires org.restlet.ext.jackson;​ 
 +    exports info.elsener.package to com.fasterxml.jackson.databind;​ 
 +    exports info.elsener.package to org.restlet.ext.jaxrs;​ 
 +</​Code>​ 
 + 
 +===== requires ===== 
 +The line '​requires org.restlet.ext.jackson;'​ is needed to provide the '​JacksonConverter'​ to your project. Otherwise it will not be automatic recognized by restlet. 
 +==== exports ==== 
 +The lines '​exports ....' will allow jaxrs and jackson to read and write your Input/​Output-Types. 
 + 
 + 
 + 
java/restlet/jackson.txt · Last modified: 2018/08/01 09:52 by els