java - How do I register the Jackson provider with the Wink client? -


i'm trying set toy application (which may turn in real application someday). i'm running problem wink , jackson. i've got 2 applications: 1 runs wink-server on jetty , seems providing json data fine; 1 runs wink-client on jetty , receives json data fine. problem lies in automagically deserializing json data java bean.

here's code use in wink client action:

restclient client = new restclient(); resource resource = client.resource("http://localhost:8081/helloworld"); user user = resource.accept(mediatype.application_json).get(user.class); 

here's error receive when try run struts action:

java.lang.runtimeexception: no javax.ws.rs.ext.messagebodyreader found type class my.package.structure.user , media type application/json. verify entity providers correctly registered. org.apache.wink.client.internal.handlers.clientresponseimpl.readentity(clientresponseimpl.java:123) org.apache.wink.client.internal.handlers.clientresponseimpl.getentity(clientresponseimpl.java:65) org.apache.wink.client.internal.handlers.clientresponseimpl.getentity(clientresponseimpl.java:52) org.apache.wink.client.internal.resourceimpl.invoke(resourceimpl.java:186) org.apache.wink.client.internal.resourceimpl.get(resourceimpl.java:294) my.package.structure.action.helloworldaction.execute(helloworldaction.java:29) ... 

if replace last line in first code snippet following line, works fine , dandy.

string message = resource.accept(mediatype.application_json).get(string.class); objectmapper mapper = new objectmapper(); user user = mapper.readvalue(message, user.class); 

it's clear data getting across fine, problem seems lie fact jacksonjsonprovider class not registered wink client. i've seen lot of ways register provider wink server, not wink client.

is possible make first code snippet operate properly? if so, how?

(as aside, other problem may i'm missing annotations on user class. right there aren't any. maybe need some...)

step 1: create class extends javax.ws.rs.core.application allows set singletons.

import java.util.collections; import java.util.set; import javax.ws.rs.core.application;  public class clientapplication extends application {      private set<object> singletons = collections.emptyset();      @override     public set<object> getsingletons() {         return singletons;     }      public void setsingletons(final set<object> singletons) {         this.singletons = singletons;     } } 

step 2: in action, create org.apache.wink.client.clientconfig org.apache.wink.client.restclient. allows add org.codehaus.jackson.jaxrs.jacksonjsonprovider providers list.

clientapplication clientapplication = new clientapplication(); set<object> s = new hashset<object>(); s.add(new jacksonjsonprovider()); clientapplication.setsingletons(s); clientconfig clientconfig = new clientconfig().applications(clientapplication); restclient restclient = new restclient(clientconfig); 

step 3: create org.apache.wink.client.resource, use get(class<t> responseentity) method , work expected.

resource resource = client.resource("http://localhost:8081/helloworld"); user user = resource.accept(mediatype.application_json).get(user.class); 

if want slick it, can use spring set clientconfig bean , inject in actions. then, can call new restclient(clientconfig) every time , not worry replicating entire setup.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -