I have an abstract class called Instance
and then two implementations of that, UserInstance
and HardwareInstance
. The issue I am having is that when I call the rest endpoint for a @POST
into the database, I ideally wanted it to be like .../rest/soexample/instance/create
where the instance is passed to the REST endpoint. If Instance
wasn't abstract with more than one implementation it would be fine, but since I have 2 I am getting a Jackson.databind
error.
" problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information"
After looking up a solution to this I found a SO answer that said I could use something like:
@JsonDeserialize(as=UserInstance.class)
But it seem's like that isonly useful if there is one implementation of the abstract class. Assuming I can't call it twice since there would be no way for it to decide which type of instance it would be.
So I am wondering what is the best way to handle this situation? Should I create different endpoints? Like:
.../rest/soexample/userinstance/create
& .../rest/soexample/hardwareinstance/create
I am not too sure as I am a noobie @ REST related things, though actively trying to learn. Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…