我有要与Jackson和Lombok进行序列化/反序列化的类
@Getter
@NoArgsConstructor
@JsonInclude(NON_NULL)
public class Hostel<T> {
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, property="@class")
protected @Valid T place;
public Hostel(T place) {
this.place = place;
}
}
@Data
@NoArgsConstructor
@JsonInclude(NON_NULL)
public class MyHostel extends Hostel<Country> {
@Builder
public MyHostel(Country country) {
super(country);
}
}
但是在序列化和反序列化时出现此错误
org.springframework.http.converter.HttpMessageNotReadableException:
JSON parse error: Missing type id when trying to resolve subtype of [simple type, class Country]: missing type id property '@class' (for POJO property 'place');
nested exception is com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id
when trying to resolve subtype of [simple type, class Country]: missing type id property '@class' (for POJO property 'place')