Поле Java DTO имеет несколько типов? [закрыто] ⇐ JAVA
-
Гость
Поле Java DTO имеет несколько типов? [закрыто]
I am creating a POST request API. The accountItems class member can be of two different Types. E.g.: Class Food and Class Car.
Both Classes have two member names which are different and important. (Because its calling an external API). Right now, I'm using a List. I tried using an interface, but was getting different error. Is there any way to have type safety, or is HashMap the best option?
@Data public class AccountRequest { private String accountId; private List accountItems; } @Data public class Food { private String foodItem; private String foodDescription; } @Data public class Car { private String cardId; private String carDescr; } Interface Attempt Error:
nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of class (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
This resource attempt did not work: How to define a field to have multiple types?
Источник: https://stackoverflow.com/questions/781 ... iple-types
I am creating a POST request API. The accountItems class member can be of two different Types. E.g.: Class Food and Class Car.
Both Classes have two member names which are different and important. (Because its calling an external API). Right now, I'm using a List. I tried using an interface, but was getting different error. Is there any way to have type safety, or is HashMap the best option?
@Data public class AccountRequest { private String accountId; private List accountItems; } @Data public class Food { private String foodItem; private String foodDescription; } @Data public class Car { private String cardId; private String carDescr; } Interface Attempt Error:
nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of class (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
This resource attempt did not work: How to define a field to have multiple types?
Источник: https://stackoverflow.com/questions/781 ... iple-types
Мобильная версия