当解组具有即时数据类型的对象时,我将得到以下异常。有什么建议可以解决这个问题吗?
我试图用java 8即时数据类型来解决这个问题,不喜欢转换为LocalDate或其他数据类型。
Exception in thread "main" java.lang.IllegalArgumentException: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of java.time.Instant: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: [{"transactionType":"ADD_DOC","payload":{"hash":"hashofthedocument12","userId":"123","meta":{"key1":"data1","key2":"data2"}},"consensusTimestamp":{"epochSecond":1522205987,"nano":533000000},"id":"2aaa3863-062d-4fcc-a789-8aad3dfade57"}]; line: 1, column: 148] (through reference chain: java.lang.Object[][0]->ipos.hashgraph.model.ConsensedDocument["consensusTimestamp"])
at ipos.hashgraph.marshaller.JacksonMarshaller.unmarshalLenient(JacksonMarshaller.java:50)
at ipos.hashgraph.loadtest.LoadTestor.getTransaction(LoadTestor.java:61)
at ipos.hashgraph.loadtest.LoadTestor.main(LoadTestor.java:99)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of java.time.Instant: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: [{"transactionType":"ADD_DOC","payload":{"hash":"hashofthedocument12","userId":"123","meta":{"key1":"data1","key2":"data2"}},"consensusTimestamp":{"epochSecond":1522205987,"nano":533000000},"id":"2aaa3863-062d-4fcc-a789-8aad3dfade57"}]; line: 1, column: 148] (through reference chain: java.lang.Object[][0]->ipos.hashgraph.model.ConsensedDocument["consensusTimestamp"])代码:
ObjectMapper mapper = new ObjectMapper();
mapper.findAndRegisterModules();
try {
mapper.readValue(responseEntity1.getBody(), ConsensedDocument[].class);
} catch (IOException e) {
e.printStackTrace();
}模型对象
String transactionType;
Document payload;
Instant consensusTimestamp;
UUID id;发布于 2018-03-28 03:50:28
您需要一个外接程序来支持JSR-310,试着遵循下面的示例:https://github.com/FasterXML/jackson-modules-java8
https://stackoverflow.com/questions/49525727
复制相似问题