[REQ] Cleanup Jackson type info mess
Created by: rpost
General question: why some java generators use JsonTypeInfo.As.EXISTING_PROPERTY
and some JsonTypeInfo.As.PROPERTY
?
More specific question: why spring-java generator for following specification snippet:
Service:
type: object
discriminator:
propertyName: '@type'
required:
- '@type'
properties:
'@type':
description: JSON type discriminator, must contain object type name
type: string
ConcreteService:
allOf:
- $ref: '#/components/schemas/Service'
- type: object
creates sources as follows:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "@type", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = ConcreteService.class, name = "ConcreteService"),
})
public class Service {
@JsonProperty("@type")
private String atType;
?
Why is discriminator value exposed as object property? It should be invisibile from java developer point of view. What is even worse is that I have to manually set proper type in order to have @type
filled in serialized json.
Considering yaml above I would expect that
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@type", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = ConcreteService.class, name = "ConcreteService"),
})
public class Service {
// no @type property!
is created.