我正在尝试反序列化一个看起来像这样的JSON对象:
{"payload":"cGF5bG9hZA==",
"verifier":{"id":"00000000-0000-0001-0000-000000000002",
"accountId":"00000000-0000-0003-0000-000000000004"}}
通过此电话:
VerifiedPayload<VerifierType> verifiedPayload = new ObjectMapper().readValue(jsonVerifiedPayload, new TypeReference<VerifiedPayload<VerifierType>>() {});
我收到了错误:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `tech.dashman.common.JSONable` (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: (String)"{"payload":"cGF5bG9hZA==","verifier":{"id":"00000000-0000-0001-0000-000000000002","accountId":"00000000-0000-0003-0000-000000000004"}}"; line: 1, column: 38] (through reference chain: tech.dashman.common.crypto.VerifiedPayload["verifier"])
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1438)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1027)
at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:265)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:519)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeWithErrorWrapping(BeanDeserializer.java:527)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:416)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1265)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:325)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4001)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3011)
at tech.dashman.common.crypto.AsymEncryptedData.decrypt(AsymEncryptedData.java:82)
VerifiedPayload
看起来像这样:
@Data
@NoArgsConstructor
@AllArgsConstructor
class VerifiedPayload<VerifierType extends JSONable> implements JSONable {
private byte[] payload;
private VerifierType verifier;
}
在这种情况下,和VerifierType
是类Verifier
,如下所示:
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Verifier implements JSONable {
private UUID id;
private UUID accountId;
}
看起来它正在尝试构建JSONable
而不是VerifiedPayload<VerifierType>>
。
我在这里做错了什么?