question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@JsonTypeInfo visible=true serialises the field twice

See original GitHub issue

Spun off from #250.

The below code will add a name field twice into the serialised JSON:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "name", visible = true)
public static abstract class Fruit {
    // @JsonIgnore
    public abstract String getName();
}

Adding in the @JsonIgnore is a workaround but I cannot imagine a circumstance where I would want that behaviour. This ticket is requesting a “visible” property be ignored by default during serialisation.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
cowtowncodercommented, Jul 25, 2013

Oh. How quickly do I forget features I add. The REAL answer is that there is specific annotation – @JsonTypeId – to be used to indicate property that gives type id value. Its name may be same as specified by propertyName, but need not be; similarly, this id may be used with any inclusion methods (as-wrapper-array, as-wrapper-object, external-property).

1reaction
cowtowncodercommented, Jul 25, 2013

Ok, so the current idea (wrt existing code) is that instead of @JsonIgnore, you should use @JsonTypeId. Whether you want visible=true or not depends on what you are trying to achieve: it is only needed if you have a matching setter. Setting of visible does not actually come into play here; rather it is just missing linkage between type id (which happens to be marked to be added as ‘name’) and regular property.

Still… it seems odd to add duplicate entries regardless. Question then becomes: which mechanism should be used for figuring out type id to use? If @JsonTypeId is used, answer seems clear: use the property (via getter or field access). Without it, it seems logical that type id should be generated instead.

I will try to see how to do such supression. Please let me know if I misunderstood anything from above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jackson - @JsonTypeInfo property is being mapped as null?
As.PROPERTY, property = "exercise_type", visible = true) ... 'visible' true in JsonTypeInfo will help in accessing exercise_type as a field.
Read more >
Type info is not serialized when a @JsonTypeInfo element is a ...
@JsonTypeInfo (include = As.PROPERTY, use = Id.CLASS) ... Ideally it would be possible to avoid double serialization (hence
Read more >
Serialization with Jackson - Documentation - Akka
Jackson support for Scala Enumerations defaults to serializing a Value as a JsonObject that includes a field with the "value" and a field...
Read more >
JsonTypeInfo (Jackson-annotations 2.4.0 API) - FasterXML
Annotation used for configuring details of if and how type information is used with JSON serialization and deserialization, to preserve information about ...
Read more >
Inheritance in Jackson | Baeldung
There are two ways to add type information when serializing and ... is used to verify that the actual subtypes to deserialize are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found