jsoninheritanceblaze-persistence

Blaze Persistence EntityView inheritance mapping


I'm currently using Quarkus combined with Blaze Persistence for my microservice. I have the following entity model:

@Entity
public class Content extends BaseEntity {
    private boolean deleted;
    private boolean published;
}

@Entity
public class WebContent extends Content {
    private String webpage;
}

I've mapped the entities to the following EntityViews:

@EntityView(Content.class)
@EntityViewInheritance
@CreatableEntityView
@UpdatableEntityView
public interface ContentUpdateView {
    @IdMapping
    Long getId();
    boolean isPublished();
    void setPublished(boolean published);
}

@EntityView(WebContent.class)
@CreatableEntityView
@UpdatableEntityView
public interface WebContentUpdateView extends ContentUpdateView {
    String getWebpage();
    void setWebpage(String webpage);
}

I have the following method in my ContentsResource:

@POST
public ContentUpdateView save(ContentUpdateView content) {
    return contentsService.save(content);
}

When I invoke the post operation I only get the base ContentUpdateView and not the WebContentUpdateView. Is there any configuration to do? (with Jackson I use @JsonTypeInfo and @JsonSubType annotation on the entities to accomplish this).

Thanks euks


Solution

  • I got it working using Jackson annotation. Here's the base class:

    @EntityView(Content.class)
    @EntityViewInheritance
    @JsonTypeInfo(
            use = JsonTypeInfo.Id.NAME,
            property = "type")
    @JsonSubTypes({
            @JsonSubTypes.Type(value = DescriptiveContentView.class, name = "descriptive"),
            @JsonSubTypes.Type(value = MediaContentView.class, name = "media"),
            @JsonSubTypes.Type(value = WebContentView.class, name = "web")
    })
    @JsonTypeName("content")
    public abstract class ContentView {
        @IdMapping
        public abstract Long getId();
        public abstract boolean isPublished();
    }
    

    And here's a subclass:

    @EntityView(DescriptiveContent.class)
    @JsonTypeName("descriptive")
    public abstract class DescriptiveContentView extends ContentView {
        public abstract Set<LocalizedParagraphView> getLocalizedParagraphs();
    }
    

    I'm using abstract classes for other purposes, but it also works with interfaces.