Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization fails because PropertyParser gets confused by getter methods with one parameter #112

Open
AlbrechtStriffler opened this issue May 14, 2017 · 2 comments
Assignees
Labels

Comments

@AlbrechtStriffler
Copy link

Hey,
I'm using GWTP with gwtp-dispatch-rest version 1.6, which uses gwt-jackson version 0.14.1.
Gwt-jackson is used for the DTO serialization.

Basically, I had the following DTO:

public class MyDto {

    List<NestedDto> nestedDtos = new ArrayList<NestedDto>();

    public void setNestedDtos(List<NestedDto> nestedDtos) {
        this.nestedDtos = nestedDtos;
    }

    public List<NestedDto> getNestedDtos() {
        return this.nestedDtos;
    }

    public List<NestedDto> getNestedDtos(String someFilter) {
        List<NestedDto> filteredDtos = new ArrayList<NestedDto>();
        // add nestedDtos that fit the filter...
        return filteredDtos
    }

}

Gwt-jackson did not automatically generate deserializers for List<NestedDto> nestedDtos, because the PropertyParser seemingly got confused when parsing the methods of MyDto.
In the current git master (0.14.3-SNAPSHOT), but probably since some time, PropertyParser#parseMethods(...) adds all methods as a setter to PropertyAccessorsBuilder, that have on parameter and fit the property name 'nestedDtos'. Since the getter with the filter also fits the constraint of having one parameter, it is also added as as setter, although it is a getter.
If that getter is also the first 'setter' to be added for that builder, it will then be the setter for that Property (even if there are multiple other correct setters).

Later in the build process, in the PropertyProcessor#processProperty(...), you check whether the setter is auto detected. This fails, because the setter does not start with "set", see PropertyProcessor#isSetterAutoDetected(...) line 331. Because of this, no setter is added to the builder and ultimately the serialization/deserialization fails. (My actual DTO was quite a bit more complex and my specific exception was due to some other failure even later, when a NestedDto was referenced, although it was never deserialized because of that getter-setter issue.)

In the end, for me the solution was just to slightly rename the method into 'getNestedDtosFiltered(...)' so it no longer was recognized as a setter.
I also tried to mark the correct setter with @JsonSetter or @JsonAnySetter and later the wrong 'setter' with @JsonIgnore (although the semantic of @JsonIgnore is a bit different afaik). Both did not seem to help. Please let me know, if I used these annotations in the wrong way (or if there would have been a combination that should have worked).

My guess is, that you should probably check the type of the method parameter, if the method does not start with 'set' in the PropertyParser... or maybe have a look at how @JsonSetter is used.

Thanks
Albrecht

@nmorel
Copy link
Owner

nmorel commented May 14, 2017

Thanks for the detailed report :)

I added a small hack for this case.
It requires a lot more work to handle all the cases and I won't have time for it right now.

@AlbrechtStriffler
Copy link
Author

Great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants