3

I have a class that I'm exposing via Spring Data REST, it looks like this, getters and setters, as well as irrelevant fields, are omitted:

public class System {
    @NotNull
    @Valid
    @OneToOne(optional = false, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval = true)
    @JoinColumn(name = "FLOW_ID")
    private FlowConfig flow;
}

FlowConfig itself isn't exposed via a RestRepository, it looks like this:

@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "@type")
//@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@type")
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = "FLOWCONFIG")
@Audited
public abstract class FlowConfig extends BaseEntity {
    // Some fields, none of them representing the type of the entity
}

The problem is that both @JsonTypeInfo annotations don't work, I never get type information in the JSON output. Whatever I put, I never get the @type in the resulting JSON.

According to this link, EXISTING_PROPERTY should work, but it doesn't. If I test JSON output with a default ObjectMapper, both annotations produce what I want.

Any ideas what I'm doing wrong? I'm on version 2.6.9 of spring-data-rest-webmvc.

Thanks!

N4zroth
  • 1,334
  • 2
  • 10
  • 25

0 Answers0