Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Jackson: Use 'As.EXISTING_PROPERTY' in super types with discriminator #331

Closed
alxgrk opened this issue Feb 7, 2018 · 5 comments
Closed

Comments

@alxgrk
Copy link

alxgrk commented Feb 7, 2018

Hi,

when generating types with Jackson option turned on, the following is generated for types that declare a discriminator:

@JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME,
    include = JsonTypeInfo.As.PROPERTY,
    property = "type"
)
@JsonSubTypes({
    @JsonSubTypes.Type(B.class)
})
public interface A {
  String getType();
}

The subtype B overriding the discriminatorValue with e.g. "B" would then look something like this:

public interface B extends A {
  String getType();

  String getAnotherProp();

  void setAnotherProp(String anotherProp);
}

However, if this is getting serialized, the resulting output string will contain the type property twice, since @JsonTypeInfo(..., include = As.PROPERTY) should actually be @JsonTypeInfo(..., include = As.EXISTING_PROPERTY).

As this is probably the case for every inheritance type structure using discriminator, could you please fix this?

Regards,
Alex

jpbelang added a commit that referenced this issue Feb 18, 2018
@jpbelang
Copy link
Contributor

Could you check 3.0.0-SNAPSHOT ? I can't seem to get the behaviour you are describing.

@jpbelang jpbelang added this to In progress in 3.0.0 Feb 18, 2018
@jstoiko jstoiko closed this as completed Mar 20, 2018
3.0.0 automation moved this from In progress to Done Mar 20, 2018
@jstoiko
Copy link
Contributor

jstoiko commented Mar 20, 2018

3.0 released. Feel free to re-open this issue or create a new one if it doesn't work as expected

@JoergAdler
Copy link

JoergAdler commented Jun 4, 2018

We are still seeing this behavior wir 3.0.1 (using jackson 2.8.7 for serialization) Another possible solution would be to add an "@JsonTypeId" to the implementing type.

@alxgrk
Copy link
Author

alxgrk commented Jun 4, 2018

Sorry for not responding lately, I just tried it out again as well and obviously the problem still exists...

@JoergAdler
Copy link

The reason of this behavior is handled in the following merge request. Would be nice, if you woulf consider to merge it.

mulesoft-labs/raml-java-tools#13

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
3.0.0
  
Done
Development

No branches or pull requests

4 participants