Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-3055

RESTEasy can't deserialize subtypes (JSON)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not a Bug
    • Icon: Major Major
    • None
    • 4.7.2.Final
    • jaxrs
    • None
    • Hide

      Start the nodejs server: 

      node server.js

       (server.js is in the attached zip file). This node server replies with a sample json at localhost:3000/test

      Run the main method in class

      agori.sample.TestRest

      It should fail.

      Alternatively test the code using the Wildfly runtime. Deploy the webapp in attachment and call url localhost:8080/webapp-sample/api/test/ (this should return the very same error of the main class)

      To prove that nothing is wrong with the annotations (or the JSON snippet), run localhost:8080/webapp-sample/api/test/useString where the deserialization is done "manually", that is asking RESTeasy to return a string and converting the string to the DTO using a new ObjectMapper. This should succeed.

      Show
      Start the nodejs server:  node server.js  (server.js is in the attached zip file). This node server replies with a sample json at localhost:3000/test Run the main method in class agori.sample.TestRest It should fail. Alternatively test the code using the Wildfly runtime. Deploy the webapp in attachment and call url localhost:8080/webapp-sample/api/test/ (this should return the very same error of the main class) To prove that nothing is wrong with the annotations (or the JSON snippet), run localhost:8080/webapp-sample/api/test/useString where the deserialization is done "manually", that is asking RESTeasy to return a string and converting the string to the DTO using a new ObjectMapper. This should succeed.
    • Workaround Exists
    • Hide

      return a string and parse it using ObjectMapper.readValue.

      Show
      return a string and parse it using ObjectMapper.readValue.

      This happens with Java17, Wildly-25.0.1.Final

       

      RESTeasy client can't deserialize a json with subtypes.

       

      Client client = ResteasyClientBuilder.newBuilder().build();        
      client.target("http://localhost:3000/test")
              .request()
              .get(Resource.class);
       
      

      JSON snippet (produced by jackson2):

      {
        "type": "agori.sample.dto.Concept",
        "id": "wmt_food_configuration_c0",
        "prefLabel": "Food Configuration"
      }

      Error: 

      Could not resolve type id 'agori.sample.dto.Concept' as a subtype of `agori.sample.dto.Resource`: Configured `PolymorphicTypeValidator` (of type `com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator`) denied resolution at [Source: (org.jboss.resteasy.specimpl.AbstractBuiltResponse$InputStreamWrapper); line: 3, column: 11]

              Unassigned Unassigned
              lagoria Alberto Gori (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: