【发布时间】:2019-06-03 17:58:35
【问题描述】:
您好,我在客户端使用了 LogEvent 对象来记录事件,我想使用 REST API 将其发送到服务器。我正在将 LogEvent 对象转换为 json 字符串并通过 REST 将其作为有效负载发送。 在服务器端,我使用的是 Groovy,当我尝试执行 objectMapper.readValue() 时,出现以下错误。
com.fasterxml.jackson.databind.JsonMappingException:找不到非具体集合类型的反序列化器[集合类型; org.apache.logging.log4j.ThreadContext$ContextStack 类,包含[简单类型,类 java.lang.String]]
/// Client Side code.
private final List<LogEvent> eventQueue = new LinkedList<>();
List<LogEvent> logToSend;
eventsToSend = new ArrayList<>(eventQueue);
String jsonLogStream = new String();
ObjectMapper mapperObj = new ObjectMapper();
try{
jsonLogStream = mapperObj.writeValueAsString(logToSend);
}catch (IOException e){
e.printStackTrace();
}
closeableHttpResponse = communicationManager.executeHttpPost(uri, Collections.emptyMap(), new ByteArrayInputStream(jsonLogStream.getBytes()), false);
//// In Groovy
//
String logstream = request.getJSON().toString()
//here I'm getting LogEvents converted to json
LogEvent[] events = mapper.readValue(logstream, LogEvent[].class )
// mapper.readvalue giving error mentioned.
我无法使用 ObjectMapper 将 json 转换回对象。 谢谢你的帮助。
【问题讨论】:
标签: java json rest log4j objectmapper