glassfish
  1. glassfish
  2. GLASSFISH-20515

[fishcat] codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "name" (Class com.demo.User), not marked as ignorable

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 4.0_b88_RC4
    • Fix Version/s: 4.1.1
    • Component/s: jax-rs
    • Labels:
      None
    • Environment:

      Description

      I used Netbeans to generate a jax-rs resources and config to test a jax-rs application.

      I also used Netbeans to generate the jax-rs client from the HelloResources.

      The problem is when I try to consume a "application/json" into a User object. I obtain this stacktrace in GF 4.0 latest promoted build.

      I'll provide the source code at the end of the stacktrace.

      INFO: class com.demo.CDIManagedBean post construct
      INFO: class com.demo.HelloResource post construct
      WARNING: StandardWrapperValve[org.netbeans.rest.application.config.ApplicationConfig]: Servlet.service() for servlet org.netbeans.rest.application.config.ApplicationConfig threw exception
      org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "name" (Class com.demo.User), not marked as ignorable
      at [Source: org.glassfish.jersey.message.internal.EntityInputStream@d03ff; line: 1, column: 10] (through reference chain: com.demo.User["name"])
      at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)
      at org.codehaus.jackson.map.deser.StdDeserializationContext.unknownFieldException(StdDeserializationContext.java:267)
      at org.codehaus.jackson.map.deser.std.StdDeserializer.reportUnknownProperty(StdDeserializer.java:673)
      at org.codehaus.jackson.map.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:659)
      at org.codehaus.jackson.map.deser.BeanDeserializer.handleUnknownProperty(BeanDeserializer.java:1365)
      at org.codehaus.jackson.map.deser.BeanDeserializer._handleUnknown(BeanDeserializer.java:725)
      at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:703)
      at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
      at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)
      at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1315)
      at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
      at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:181)
      at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:134)
      at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundReadFrom(MappableExceptionWrapperInterceptor.java:72)
      at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:134)
      at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:828)
      at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:833)
      at org.glassfish.jersey.server.ContainerRequest.readEntity(ContainerRequest.java:245)
      at org.glassfish.jersey.server.internal.inject.EntityParamValueFactoryProvider$EntityValueFactory.get(EntityParamValueFactoryProvider.java:96)
      at org.glassfish.jersey.server.internal.inject.AbstractHttpContextValueFactory.provide(AbstractHttpContextValueFactory.java:66)
      at org.glassfish.jersey.server.spi.internal.ParameterValueHelper.getParameterValues(ParameterValueHelper.java:81)
      at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$AbstractMethodParamInvoker.getParamValues(JavaResourceMethodDispatcherProvider.java:121)
      at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$VoidOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:136)
      at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:91)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:346)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:341)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:101)
      at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:224)
      at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
      at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
      at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
      at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:198)
      at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:946)
      at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:323)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:218)
      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
      at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
      at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
      at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
      at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
      at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
      at java.lang.Thread.run(Thread.java:722)

      package com.demo;
      
      import javax.xml.bind.annotation.XmlAccessType;
      import javax.xml.bind.annotation.XmlAccessorType;
      import javax.xml.bind.annotation.XmlRootElement;
      
      /**
       *
       * @author sdionne1
       */
      @XmlRootElement
      @XmlAccessorType(XmlAccessType.FIELD)
      public class User {
          
          public String name;
          public String lastname;
      
      }
      
      package com.demo;
      
      import javax.annotation.PostConstruct;
      import javax.inject.Inject;
      import javax.ws.rs.Consumes;
      import javax.ws.rs.GET;
      import javax.ws.rs.POST;
      import javax.ws.rs.Path;
      import javax.ws.rs.Produces;
      
      /**
       *
       * @author sdionne1
       */
      @Path("hello")
      public class HelloResource {
          
          @Inject            
          CDIManagedBean bean;
          
          @Inject
          EJBManagedBean ejb;
          
          @PostConstruct
          public void init(){
              System.out.println(HelloResource.class + " post construct");
          } 
          
          @GET
          @Produces("text/plain")
          public String getHello(){
              return "hello : " + bean.getOutput() + "  : " + ejb.getOutput();
          }
          
          @POST
          @Consumes("text/plain")
          public void sayHello(String message){
              System.out.println("Say Hello : " + message);
          }
          
          @POST
          @Consumes("application/json")
          public void helloJson(User user){
              System.out.println("helloJson user : " + user);
          }
      }
      
      /*
       * To change this template, choose Tools | Templates
       * and open the template in the editor.
       */
      
      package com.demo;
      
      import com.sun.jersey.api.client.Client;
      import com.sun.jersey.api.client.UniformInterfaceException;
      import com.sun.jersey.api.client.WebResource;
      
      /**
       * Jersey REST client generated for REST resource:HelloResource [hello]<br>
       * USAGE:
       * <pre>
       *        NewJerseyClient client = new NewJerseyClient();
       *        Object response = client.XXX(...);
       *        // do whatever with response
       *        client.close();
       * </pre>
       *
       * @author sdionne1
       */
      public class NewJerseyClient {
          private WebResource webResource;
          private Client client;
          private static final String BASE_URI = "http://localhost:8080/WebApplication1/resources";
      
          public NewJerseyClient() {
              com.sun.jersey.api.client.config.ClientConfig config = new com.sun.jersey.api.client.config.DefaultClientConfig();
              client = Client.create(config);
              webResource = client.resource(BASE_URI).path("hello");
          }
      
          public void helloJson(Object requestEntity) throws UniformInterfaceException {
              webResource.type(javax.ws.rs.core.MediaType.APPLICATION_JSON).post(requestEntity);
          }
      
          public String getHello() throws UniformInterfaceException {
              WebResource resource = webResource;
              return resource.accept(javax.ws.rs.core.MediaType.TEXT_PLAIN).get(String.class);
          }
      
          public void sayHello(Object requestEntity) throws UniformInterfaceException {
              webResource.type(javax.ws.rs.core.MediaType.TEXT_PLAIN).post(requestEntity);
          }
      
          public void close() {
              client.destroy();
          }
          
          public static void main(String[] args){
              NewJerseyClient client = new NewJerseyClient();
              
              User user = new User();
              user.name="name1";
              user.lastname="lastname2";
              
              client.helloJson(user);
              
              client.close();
          }
      }
      

        Activity

        Hide
        survivant added a comment -

        wierd. The code wasn't right when I saved it in the previous comment.

        try

        { Class jsonProvider = Class.forName("org.glassfish.jersey.jackson.JacksonFeature"); // Class jsonProvider = Class.forName("org.glassfish.jersey.moxy.json.MoxyJsonFeature"); // Class jsonProvider = Class.forName("org.glassfish.jersey.jettison.JettisonFeature"); resources.add(jsonProvider); }

        catch (ClassNotFoundException ex)

        { java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, null, ex); }

        addRestResourceClasses(resources);
        return resources;
        }

        private void addRestResourceClasses(Set<Class<?>> resources)

        { resources.add(com.demo.HelloResource.class); }
        Show
        survivant added a comment - wierd. The code wasn't right when I saved it in the previous comment. try { Class jsonProvider = Class.forName("org.glassfish.jersey.jackson.JacksonFeature"); // Class jsonProvider = Class.forName("org.glassfish.jersey.moxy.json.MoxyJsonFeature"); // Class jsonProvider = Class.forName("org.glassfish.jersey.jettison.JettisonFeature"); resources.add(jsonProvider); } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, null, ex); } addRestResourceClasses(resources); return resources; } private void addRestResourceClasses(Set<Class<?>> resources) { resources.add(com.demo.HelloResource.class); }
        Hide
        survivant added a comment -

        I created a new project and Netbeans dev, this time found some JSON providers.

        Personnaly, I think Netbeans shouldn't override the method : getClasses(...) and let the container auto-detect the providers.

        That method should be use if you want to force a provider, if not, the code won't be portable unless we add specific jars in the war.

        My goal was to create a simple demo to show JSON -> Pojo with jax-rs that will work "out-of-the-box" in GF4 or Wildfly.. any JavaEE6 ou Java7 container without specific jax-rs implementation.

        package org.netbeans.rest.application.config;

        import java.util.Set;
        import javax.ws.rs.ApplicationPath;
        import javax.ws.rs.core.Application;

        /**
        *

        • @author sdionne1
          */
          @ApplicationPath("resources")
          public class ApplicationConfig extends Application {

        /**

        • Do not modify addRestResourceClasses() method.
        • It is automatically re-generated by NetBeans REST support to populate
        • given list with all resources defined in the project.
          */
          @Override
          public Set<Class<?>> getClasses()
          Unknown macro: { Set<Class<?>> resources = new java.util.HashSet<Class<?>>(); // following code can be used to customize Jersey 2.0 JSON provider}

        private void addRestResourceClasses(Set<Class<?>> resources)

        { resources.add(com.demo.HelloResource.class); }

        }

        Show
        survivant added a comment - I created a new project and Netbeans dev, this time found some JSON providers. Personnaly, I think Netbeans shouldn't override the method : getClasses(...) and let the container auto-detect the providers. That method should be use if you want to force a provider, if not, the code won't be portable unless we add specific jars in the war. My goal was to create a simple demo to show JSON -> Pojo with jax-rs that will work "out-of-the-box" in GF4 or Wildfly.. any JavaEE6 ou Java7 container without specific jax-rs implementation. package org.netbeans.rest.application.config; import java.util.Set; import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application; /** * @author sdionne1 */ @ApplicationPath("resources") public class ApplicationConfig extends Application { /** Do not modify addRestResourceClasses() method. It is automatically re-generated by NetBeans REST support to populate given list with all resources defined in the project. */ @Override public Set<Class<?>> getClasses() Unknown macro: { Set<Class<?>> resources = new java.util.HashSet<Class<?>>(); // following code can be used to customize Jersey 2.0 JSON provider} private void addRestResourceClasses(Set<Class<?>> resources) { resources.add(com.demo.HelloResource.class); } }
        Hide
        Jakub Podlesak added a comment -

        Deferred to 4.0.1.

        Show
        Jakub Podlesak added a comment - Deferred to 4.0.1.
        Hide
        Marek Potociar added a comment -

        Updated java listing formatting in the issue desc.

        Show
        Marek Potociar added a comment - Updated java listing formatting in the issue desc.
        Hide
        survivant added a comment -

        I can provide the source code in zip if you give my your email address.

        thanks

        Show
        survivant added a comment - I can provide the source code in zip if you give my your email address. thanks

          People

          • Assignee:
            Jakub Podlesak
            Reporter:
            survivant
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: