gwt-jackson icon indicating copy to clipboard operation
gwt-jackson copied to clipboard

Deserialising back references does not work properly.

Open dnouls opened this issue 8 years ago • 2 comments

See the pull request: Pull Request

This contains a GWT test case that uses gwt-jackson and an identical regular testcase that uses jackson. With jackson this works, with gwt-jackson it fails.

dnouls avatar Apr 05 '16 15:04 dnouls

Thanks for the test case, I'll look at it.

nmorel avatar Apr 05 '16 15:04 nmorel

I just looked at it. The problem come from your constructor annotated with @JsonCreator on Owner.

To create an Owner entity, I first resolve the constructor parameters. In this case, the children's list. Since the owner is not yet created, I cannot find the owner when I resolve the children.

To solve the issue, I have to separate the instantiation and the properties resolution but that's a lot of work. I may keep that for the v2 with the APT generation.

As a workaround, you can do that :

@JsonIdentityInfo( generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id" )
public static class Owner {

    @JsonProperty( "children" )
    private List<Child> children;

    Owner() {
        this.children = new ArrayList<Child>();
    }

    Owner( List<Child> children ) {
        this.children = children;
    }

    public List<Child> getChildren() {
        return children;
    }

    public Child addChild( String name ) {
        Child child = new Child( name );
        child.setOwner( this );
        children.add( child );
        return child;
    }
}

I just moved the @JsonProperty annotation to the private field and removed the @JsonCreator annotation. You lose the ability to put your list final though.

nmorel avatar May 29 '16 09:05 nmorel