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

Changes to ResteasyJackson2Provider in 3.0.14.Final breaks Jackson2 @JsonView behavior

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Critical
    • 3.0.19.Final
    • 3.0.14.Final
    • jaxrs
    • None
    • Hide
      • create a simple DTO with two field.
      • annotate one field with something like @JsonView(View.Public.class)
      • create an API method that returns your DTO (with or without the @JsonView annotation)
      • call the method and on the server set both fields to non-null values

      The results will be that the server side will serialize all field correctly and the JSON it produces look good. But if you call this through a resteasy client the resulting object will always show the @JsonView annotated fields with a null value.

      Show
      create a simple DTO with two field. annotate one field with something like @JsonView(View.Public.class) create an API method that returns your DTO (with or without the @JsonView annotation) call the method and on the server set both fields to non-null values The results will be that the server side will serialize all field correctly and the JSON it produces look good. But if you call this through a resteasy client the resulting object will always show the @JsonView annotated fields with a null value.
    • Compatibility/Configuration, User Experience

    Description

      In line 108 in ResteasyJackson2Provider starting with version 3.0.14 you call this:

      endpoint = _configForReading(mapper, annotations, type);

      compared to this in 3.0.13:

      endpoint = _configForReading(mapper, annotations);

      So you added a 3rd parameter: the type you want to read. But if you look at the matching method declaration in com.fasterxml.jackson.jaxrs.base.ProviderBase you'll find the 3rd parameter is actually a "default view" class - not the type to read:

      _configForReading(MAPPER mapper, Annotation[] annotations, Class<?> defaultView);

      So what happens if you actually add the third parameter that is != null Jackson will check each field it deserializes for @JsonView annotations and if one is present validate assignability to the provided parameter. It it is not assignable it will skip the field.

      So bottom line this will work as long as you don't have any @JsonView annotations present on the DTO you want to read from json. If you have @JsonView annotations on a few fields it will deserialize them all to null because most likely non of the annotation values will be assignable to the type you provide as 3rd parameter.

      I think just either replacing
      endpoint = _configForReading(mapper, annotations, type);
      with
      endpoint = _configForReading(mapper, annotations, null);
      or actually supporting the @JsonView feature directly and provide an actual default view as parameter should fix the issue.

      Attachments

        Issue Links

          Activity

            People

              rhn-support-asoldano Alessio Soldano
              thorstenkunz Thorsten Kunz (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: