【发布时间】:2021-03-14 09:45:26
【问题描述】:
我有一个响应对象,它始终包含响应对象作为属性和不同类型的值,因此我在一个类中将接口作为一个字段,这样它将基于一些唯一值标识符带来正确的实现。
Could not execute the callcom.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class com.opngo.nowos.nowos.api.response.DataResponse]: missing type id property 'operation' (for POJO property 'response')
at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 180] (through reference chain: com.opngo.nowos.nowos.NowOSResponse["response"])
这是我的界面
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "operation")
@JsonSubTypes({@JsonSubTypes.Type(value = AuthResponse.class, name = "account_auth")})
public interface IResponse {
///
}
这是实现上述接口的响应对象之一
@RequiredArgsConstructor
public class AuthResponse implements IResponse {
@JsonProperty
private final String accountID;
@JsonProperty
private final String authToken;
@JsonProperty
private final String language;
}
这是具有应该带来正确响应对象的接口的主要响应
public class NowOSResponse {
@JsonProperty
private final String operation;
@JsonProperty
private final String version;
@JsonProperty
private final IResponse response;
@JsonProperty
private final String status;
}
看起来它没有查看父项并在 AuthResponse 中搜索操作字段,该字段当然是空的,因为操作字段始终存在于父项中并且该父项具有响应 -> AuthResponse ->CreateAccResponse 等等
【问题讨论】:
标签: java json jackson retrofit jackson-databind