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

The StudentPatchTest.testPatchDisabled test has different behavior with different versions of Yasson

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • None
    • None
    • None

      The StudentPatchTest.testPatchDisabled fails on Yasson 3.0.0. The test part the fails looks like this:

      jakarta.json.JsonArray patchRequest = Json.createArrayBuilder()
              .add(Json.createObjectBuilder().add("op", "copy").add("from", "/firstName").add("path", "/lastName").build())
              .add(Json.createObjectBuilder().add("op", "replace").add("path", "/firstName").add("value", "John").build())
              .build();
      Response res = patchTarget.request().build(HttpMethod.PATCH, Entity.entity(patchRequest, MediaType.APPLICATION_JSON_PATCH_JSON)).invoke();
      Assert.assertEquals("Http 400 is expected", 400, res.getStatus());
      

      On Yasson 2.x it throws the following exception which is the cause of the 400.

      jakarta.ws.rs.ProcessingException: RESTEASY008200: JSON Binding deserialization error: jakarta.json.bind.JsonbException: Can't deserialize JSON array into: class org.jboss.resteasy.test.resource.patch.Student
      

      The entity value for the above exception is:

      [{"op":"copy","from":"/firstName","path":"/lastName"},{"op":"replace","path":"/firstName","value":"John"}]
      

      With WildFly 27 where Yasson is 3.0, the result is a 200 with an empty entity {}. The difference needs to be examined. Yasson creates a new Student with all null values.

            [RESTEASY-3132] The StudentPatchTest.testPatchDisabled test has different behavior with different versions of Yasson

            I'm not sure I follow why it would be different though. The Jakarta JSON Binding 3.0 spec says the same thing.

            The test itself might be a bit wrong TBH. I don't really know why a 400 would be expected. The patching is disabled in the deployments test. However, it looks like that should just FilterFlag.SKIP is returned which should just skip the filter.

            I guess I'd really expect 200 to be correct, but I don't really know what the entity should be.

            James Perkins added a comment - I'm not sure I follow why it would be different though. The Jakarta JSON Binding 3.0 spec says the same thing. The test itself might be a bit wrong TBH. I don't really know why a 400 would be expected. The patching is disabled in the deployments test. However, it looks like that should just FilterFlag.SKIP is returned which should just skip the filter. I guess I'd really expect 200 to be correct, but I don't really know what the entity should be.

            r searls added a comment -

            Yasson:2.0.1 is used by resteasy:6.0.3.Final. 
            In 2.0.1 class org/eclipse/yasson/internal/serializer/DeserializerBuilder.java,
            method build() [line 76] performs the root processing for deserialization.
            This method checks the (entity's) rawDataType for deserializing values.
            It checks for rawTypes, Byte array, Char array, Jsonvalue type, Map type,
            Array type, Collection type and the like.  Class Student is none of these
            Exception JsonbException is thrown at line 151.

            Yasson:3.0.1 is used by resteasy:6.2.0.Final-SNAPSHOT
            In 3.0.1 class org/eclipse/yasson/internal/deserializer/ObjectDeserializer.java,
            method deserialize [line 52] processes the JSON data.  Prior to entering this
            method yasson has cached the fields of class Student into a Map.  This map
            is used to lookup the "key" of each key/value pair in the presented data, [e.g
                Json.createObjectBuilder()
                  .add("op", "copy")
                  .add("from", "/firstName")
                  .add("path", "/lastName")]
            None of the keys, op, from, or path are fields in class Student. ObjectDeserializer
            completes it's deserialization without error and passes an instance of Student
            in the request.

            The jakarta-jsonb-spec-2.0 section 3.7.1 states,

              If a JSON document contains a name/value pair not corresponding to field 
              or setter method then this name/value pair is skipped 

            so this appears to be valid behavior.

            r searls added a comment - Yasson:2.0.1 is used by resteasy:6.0.3.Final.  In 2.0.1 class org/eclipse/yasson/internal/serializer/DeserializerBuilder.java, method build() [line 76] performs the root processing for deserialization. This method checks the (entity's) rawDataType for deserializing values. It checks for rawTypes, Byte array, Char array, Jsonvalue type, Map type, Array type, Collection type and the like.  Class Student is none of these Exception JsonbException is thrown at line 151. Yasson:3.0.1 is used by resteasy:6.2.0.Final-SNAPSHOT In 3.0.1 class org/eclipse/yasson/internal/deserializer/ObjectDeserializer.java, method deserialize [line 52] processes the JSON data.  Prior to entering this method yasson has cached the fields of class Student into a Map.  This map is used to lookup the "key" of each key/value pair in the presented data, [e.g     Json.createObjectBuilder()       .add("op", "copy")       .add("from", "/firstName")       .add("path", "/lastName")] None of the keys, op, from, or path are fields in class Student. ObjectDeserializer completes it's deserialization without error and passes an instance of Student in the request. The jakarta-jsonb-spec-2.0 section 3.7.1 states,   If a JSON document contains a name/value pair not corresponding to field    or setter method then this name/value pair is skipped so this appears to be valid behavior.

              Unassigned Unassigned
              jperkins-rhn James Perkins
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: