Duplicate proprety ID with Jackson 2.9.2+

609 views
Skip to first unread message

Ondra Žižka

unread,
Apr 16, 2018, 1:31:51 PM4/16/18
to jackson-user
Hi, we use Lombok and Jackson. Our DTOs have a bit weird setup:

class SomeDTO {
    @JsonIgnore
    private int id;

    @JsonProperty("id")
    private int uid;
}

DropWizard 1.3.1 needs jackson-databind (otherwise throws NoClassDefException), so I have added it.
After upgrading Jackson to 2.9.5 (which Dw uses), Jackson (since 2.9.2) started to fail to load the models when creating the ObjectMapper, complaining about duplicate property "id".

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 
Duplicate creator property "id" (index 0 vs 1)
 at [Source: (String)"{
  "description": "patched description"}"; line: 1, column: 1]
        at com.fasterxml.jackson.databind.exc.InvalidDefinitionExc


This is because we use Lombok's @Builder, which needs @AllArgsConstructor, and Jackson started to take this constructor into account as JSON creator I assume.

The only way to fix it I have found was to get rid of the @Builder and @AllArgsConstructor. That way, Jackson works fine.

I don't know how Jackson internally works. Is there some option or workaround I could use to get over that duplicated id issue?

Thanks!
Ondrej

Tatu Saloranta

unread,
Apr 16, 2018, 2:20:54 PM4/16/18
to jackson-user
Hmmh. This does sound like a potential flaw in Creator
property/parameter handling.
Problem is that discovery and handling of Creator properties is
something separate from discovery of
"regular" properties, and reconciliation of these sets is quite tricky
(on 2.x; hoping to rewrite all of it for 3.x).
So what may happen is that there is discrepancy.

What would help is filing a new issue if it is possible to demonstrate
this with class as seen by Jackson
after Lombok processing. This should be relatively simple case, I
hope, as you have nicely created minimal
reproduction (for Lombok context). It seems like normal pruning of
properties did not work, or, possibly,
unification of separate accessors did not (since "implicit" names,
"id" vs "uid" differ).
The important piece to see is the constructor declaration along with
annotations.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages