1

I try to POST the object

    {
        "id": "SOME_ID",
        "foo": "http://localhost:8080/api/subclass-of-foo/OBJECT_ID"
    }

The Foo Class is abstract. Information about concrete class is in the link subclass-of-foo. But I get always "Cannot construct instance of Foo (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information".

I can't use @JsonDeserialize(as = Subclass.class) on Foo, because there are multiple sub-classes of Foo.

Where and how can I provide this information to fix the problem?

@Entity
@Inheritance(strategy = SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = STRING)
class abstract Foo {
  private id;
}

class Bar1 extends Foo {

}

class Bar2 extends Foo {

}

class Bar3 extends Foo {

}

@Entity
class X {
   private String id;

   @OneToOne
   private Foo foo;

}

And json payload to POST an X object:

    {
        "id": "X_ID",
        "foo": "http://localhost:8080/api/bar1/Bar1_ID"
    }
user1648825
  • 979
  • 11
  • 19

0 Answers0