Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-5444

(7.0.z) RESTEASY-1366 - Changes to ResteasyJackson2Provider in 3.0.14.Final breaks Jackson2 @JsonView behavior

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 7.0.4.CR1, 7.0.4.GA
    • None
    • REST
    • None
    • Compatibility/Configuration, User Experience
    • 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.
    • EAP 7.0.4

      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.

            rhn-support-asoldano Alessio Soldano
            rhn-cservice-bbaranow Bartosz Baranowski
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: