|
From: Weinan Li <we...@re...> - 2015-10-22 21:14:34
|
Hi Sean, If you can create a JIRA issue here: https://issues.jboss.org/projects/RESTEASY and attach the test case that would be very helpful :-) -- Weinan Li / JBoss > On Oct 23, 2015, at 2:30 AM, Sean Dawson <sea...@gm...> wrote: > > > Am putting together a couple very simplified testcases - where can I put/upload them to ? > > > On Wed, Oct 14, 2015 at 4:11 AM, Weinan Li <we...@re...> wrote: > > -- > Weinan Li / JBoss > > > > > On Oct 14, 2015, at 3:01 AM, Sean Dawson <sea...@gm...> wrote: > > > > > > Ok here's what I've figured out so far: > > > > 1. > > - I can leave off our JsonStringProvider for most things and they just work > > - so sending and returning Boolean, Integer, String all work fine (boolean and int have issues) > > - I can't send or receive Object > > - somehow, with the old way of doing things, there was an ObjectReader involved that would check JSON tokens or something and figure out that it was a String (for eg) > > > > 2. > > In the past, this got used in BodyEntityExtractor: > > Object obj = response.getEntity(method.getReturnType(), method.getGenericReturnType()); > > > > The new code uses: > > GenericType gt = null; > > if (method.getGenericReturnType() != null) > > { > > gt = new GenericType(method.getGenericReturnType()); > > } > > else > > { > > gt = new GenericType(method.getReturnType()); > > } > > Object obj = ClientInvocation.extractResult(gt, response, method.getAnnotations()); > > > > And now (due to Java8 or?), the generic return type is T which means it's not null but then cannot be used... > > > > java.lang.IllegalArgumentException: Type parameter T not a class or parameterized type whose raw type is a class > > at javax.ws.rs.core.GenericType.getClass(GenericType.java:179) > > at javax.ws.rs.core.GenericType.<init>(GenericType.java:136) > > at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:53) > > > > If I say to skip Generic Return Type's with the name T, then it mostly works fine. > > > > Any help on any of this? Thanks. > > > > > > Yeah this is useful info. Thanks Sean! Let me think about a solution to this. > > > > > On Mon, Oct 12, 2015 at 8:40 AM, Sean Dawson <sea...@gm...> wrote: > > > > We just wrote our own (I think) and then do... > > > > ResteasyProviderFactory.getInstance().providerFactory.registerProvider(JsonStringProvider.class); > > > > Client and server side. > > > > import java.io.IOException; > > import java.io.InputStream; > > import java.io.OutputStream; > > import java.lang.annotation.Annotation; > > import java.lang.reflect.Type; > > import javax.ws.rs.Consumes; > > import javax.ws.rs.Produces; > > import javax.ws.rs.WebApplicationException; > > import javax.ws.rs.core.MediaType; > > import javax.ws.rs.core.MultivaluedMap; > > import javax.ws.rs.ext.MessageBodyReader; > > import javax.ws.rs.ext.MessageBodyWriter; > > import javax.ws.rs.ext.Provider; > > import com.fasterxml.jackson.databind.ObjectMapper; > > @Provider > > @Produces(MediaType.APPLICATION_JSON) > > @Consumes(MediaType.APPLICATION_JSON) > > public class JsonStringProvider implements MessageBodyWriter<String>, MessageBodyReader<String> > > { > > @Override > > public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) > > { > > return type == String.class && MediaType.APPLICATION_JSON_TYPE.isCompatible(mediaType); > > } > > @Override > > public long getSize(String t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) > > { > > return -1; > > } > > private static final ObjectMapper mapper = new ObjectMapper(); > > @Override > > public void writeTo(String t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, > > MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException > > { > > // TODO: issue of encoding here? > > mapper.writeValue(entityStream, t); > > } > > @Override > > public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) > > { > > return type == String.class && MediaType.APPLICATION_JSON_TYPE.isCompatible(mediaType); > > } > > @Override > > public String readFrom(Class<String> type, Type genericType, Annotation[] annotations, MediaType mediaType, > > MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException > > { > > // TODO: issue of encoding here? > > return mapper.readValue(entityStream, String.class); > > } > > } > > > > > > On Sat, Oct 10, 2015 at 4:38 AM, Weinan Li <we...@re...> wrote: > > Hi Sean, > > > > Which RESTEasy JSON provider you are using? > > > > In addition, could you please provide me some codes so I can verify it? > > > > -- > > Weinan Li / JBoss > > > > > > > > > On Oct 10, 2015, at 1:12 AM, Sean Dawson <sea...@gm...> wrote: > > > > > > > > > There seems to be very little info online about this but I'm guessing most people here know that if you send a String value in the body of a REST call to RestEasy, Jackson complains. > > > > > > One of our other devs made a JsonStringProvider which seems super simple (it's readable/writable if it's a String _and_ the type is Json) and it uses a standard ObjectMapper to read/write the value/stream. > > > > > > In RE 3.0.11, it seems to work fine in our unit tests - ie. we can makes calls with Strings and things just work - both writeTo and readFrom methods get called. But in later versions (3.0.13 & 3.0.14), only the writeTo method gets hit and Jackson complains, unless we double quote the strings ("\"message\""). Most of our code is the same in both places with the exception of moving from the deprecated way of creating proxies to the new/recommended way. > > > > > > Any ideas? Is it maybe a classpath issue? Or a different way the provider needs to be registered? Or.... ? > > > > > > Thanks. > > > > > > ------------------------------------------------------------------------------ > > > _______________________________________________ > > > Resteasy-developers mailing list > > > Res...@li... > > > https://lists.sourceforge.net/lists/listinfo/resteasy-developers > > > > > > > > |