spring-bootblaze-persistence

Blaze persistence UpdatableEntityView as spring boot request body


I am trying to use blaze persistence UpdatableEntityView as the request body with spring boot. Following is the code for UpdatableEntityView

@UpdatableEntityView
@EntityView(DealListing.class)
public interface DealListingUpdateView {
    @IdMapping
    Long getId();
    void setId(Long id);

    Instant getListedOn();
    void setListedOn(Instant listedOn);
}

Following is the rest controller mapping

@PutMapping("/deal-listings/sell/{id}")
    public void test(@PathVariable Long id, @RequestBody DealListingUpdateView dealListingUpdateView){
        dealListingService.testUpdate(id, dealListingUpdateView);
}

Following is the pom.xml dependency to do the deserialization as specified in the blaze persistence document

        <dependency>
            <groupId>com.blazebit</groupId>
            <artifactId>blaze-persistence-integration-jackson</artifactId>
            <scope>compile</scope>
        </dependency>

But when i submit the request i am getting the following error

Type definition error: [simple type, class com.ilex.tradeservice.domain.view.blaze.DealListingUpdateView]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.ilex.tradeservice.domain.view.blaze.DealListingUpdateView` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information\n at [Source: (PushbackInputStream); line: 1, column: 1]


Solution

  • As you can see in the documentation, you will need the Spring Data WebMvc integration: https://persistence.blazebit.com/documentation/1.6/entity-view/manual/en_US/index.html#spring-data-webmvc-integration

    You will also have to additionally annotate your controller parameter with @EntityViewId("id")

    @PutMapping("/deal-listings/sell/{id}")
    public void test(@PathVariable Long id, @EntityViewId("id") @RequestBody DealListingUpdateView dealListingUpdateView){
            dealListingService.testUpdate(id, dealListingUpdateView);
    }