Поле Java DTO имеет несколько типов? [закрыто]JAVA

Программисты 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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»