Closed confile closed 9 years ago
Using Grails 2.4.4 with JaxRS 0.11 and the following to set custom provider in Config.groovy:
org.grails.jaxrs.doreader.disable=true org.grails.jaxrs.dowriter.disable=true
I tried to read the following object from client:
public class RoomServiceOrderDto { String id = "test"; Map<String, Integer> itemsMap = new LinkedHashMap<>() }
Therefore I created the following reader:
@Provider @Consumes("application/json") class RoomServiceOrderDtoReader extends MessageBodyReaderSupport<RoomServiceOrderDto> { @Override public RoomServiceOrderDto readFrom(MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { return new JsonSlurper().parse(new InputStreamReader(entityStream)) } }
The `RoomServiceOrderDto is sent in a POST request as body params to a RoomServiceResource which has the following post method:
`RoomServiceOrderDto
@POST @Consumes('application/json') @Produces('application/json') boolean post( @QueryParam("test") String test, RoomServiceOrderDto roomServiceOrderDto) { .... }
Here is the error I get:
ERROR container.ContainerResponse - The RuntimeException could not be mapped to a response, re-throwing to the HTTP container Message: Cannot cast object '{77c047205807f298b3=2}' with class 'groovy.json.internal.LazyMap' to class 'majestella.shared.dto.RoomServiceOrderDto' due to: org.codehaus.groovy.runtime.metaclass.MissingPropertyExceptionNoStack: No such property: 77c047205807f298b3 for class: majestella.shared.dto.RoomServiceOrderDto Line | Method ->> 24 | readFrom in majestella.RoomServiceOrderDtoReader - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 55 | readFrom in org.grails.jaxrs.support.MessageBodyReaderSupport | 490 | getEntity . . . . . in com.sun.jersey.spi.container.ContainerRequest | 123 | getValue in com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable | 86 | getInjectableValues in com.sun.jersey.server.impl.inject.InjectableValuesProvider | 153 | getParams in com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker | 183 | _dispatch . . . . . in com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker | 75 | dispatch in com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher | 302 | accept . . . . . . in com.sun.jersey.server.impl.uri.rules.HttpMethodRule | 108 | accept in com.sun.jersey.server.impl.uri.rules.ResourceClassRule | 147 | accept . . . . . . in com.sun.jersey.server.impl.uri.rules.RightHandPathRule | 84 | accept in com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule | 1542 | _handleRequest . . in com.sun.jersey.server.impl.application.WebApplicationImpl | 1473 | _handleRequest in '' | 1419 | handleRequest . . . in '' | 1409 | handleRequest in '' | 409 | service . . . . . . in com.sun.jersey.spi.container.servlet.WebComponent | 540 | service in com.sun.jersey.spi.container.servlet.ServletContainer | 715 | service . . . . . . in '' | 193 | process in org.grails.jaxrs.web.JaxrsContext$JaxrsServiceImpl | 45 | handle . . . . . . in org.grails.jaxrs.JaxrsController | 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter | 63 | doFilter . . . . . in grails.plugin.cache.web.filter.AbstractFilter | 53 | doFilter in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter | 62 | doFilter . . . . . in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter | 46 | doFilterInternal in org.grails.jaxrs.web.JaxrsFilter | 1142 | runWorker . . . . . in java.util.concurrent.ThreadPoolExecutor | 617 | run in java.util.concurrent.ThreadPoolExecutor$Worker ^ 745 | run . . . . . . . . in java.lang.Thread Error |
What did I miss?
Using Grails 2.4.4 with JaxRS 0.11 and the following to set custom provider in Config.groovy:
I tried to read the following object from client:
Therefore I created the following reader:
The
`RoomServiceOrderDto
is sent in a POST request as body params to a RoomServiceResource which has the following post method:Here is the error I get:
What did I miss?