另一个模块中的java AWS Lambda序列化对象
我正在接受一些遗留代码,并试图编写一个lambda来处理函数
函数看起来像
public Task doTask(Message message) throws Exception {
LOG.debug("debug message");
// ... more code
}
但是,参数Message
是在不同的模块中定义的(使用getter和setter)(并作为依赖项传入)。因此,我得到了一个错误:
{
"errorMessage": "An error occurred during JSON parsing",
"errorType": "java.lang.RuntimeException",
"stackTrace": [],
"cause": {
"errorMessage": "com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.mywebsite.messaging.Message, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information\n at [Source: lambdainternal.util.NativeMemoryAsInputStream@31610302; line: 1, column: 1]",
"errorType": "java.io.UncheckedIOException",
"stackTrace": [],
"cause": {
"errorMessage": "Can not construct instance of com.mywebsite.messaging.Message, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information\n at [Source: lambdainternal.util.NativeMemoryAsInputStream@31610302; line: 1, column: 1]",
"errorType": "com.fasterxml.jackson.databind.JsonMappingException",
"stackTrace": [
"com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)",
"com.fasterxml.jackson.databind.DeserializationContext.instantiationException(DeserializationContext.java:892)",
"com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:139)",
"com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1511)",
"com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1102)"
]
}
}
}
如何序列化这个甚至不在我的模块中的对象
我们将非常感谢您的任何帮助
谢谢
# 1 楼答案
看起来像com。我的网站。信息。消息是抽象类/ 界面在这种情况下:使用@JsonDeserialize将解决问题
大概是这样的:
这些链接可以帮助您: How to add custom deserializer to interface using jackson http://www.baeldung.com/jackson-exception
希望这有帮助