在将应用程序升级到 playframework 2.1.1 后,我在 jackson 中遇到了一些反序列化问题(jackson-mapper-asl-1.9.10.jar 和 jackson-core-asl-1.9.10.jar)
从播放控制台执行的、序列化到 json 和从 json 序列化的正常测试工作正常。当在应用程序内部使用相同的序列化时,它会像您在堆栈跟踪中看到的那样抱怨。
我的印象是,因为 akka 库,类路径受到了某种影响。
该代码使用两个函数
public static <T> String toJson(T data) {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(Feature.INDENT_OUTPUT, true);
try {
return mapper.writeValueAsString(data);
} catch (IOException e) {
LOG.warn("can't format a json object from [" + data + "]", e);
return null;
}
//
// return Json.stringify(Json.toJson(data));
}
public static <T> T fromJson(String description, Class<T> theClass) {
try {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode parse = objectMapper.readValue(description, JsonNode.class);
T fromJson = objectMapper.treeToValue(parse, theClass);
return fromJson;
} catch (JsonParseException e) {
throw new RuntimeException("can't parse a json object of type " + theClass.getName() + " from ["
+ description + "]", e);
// LOG.warn("can't parse a json object from [" + description + "]", e);
// return null;
} catch (JsonMappingException e) {
throw new RuntimeException("can't parse a json object of type " + theClass.getName() + " from ["
+ description + "]", e);
// LOG.warn("can't parse a json object from [" + description + "]", e);
// return null;
} catch (IOException e) {
throw new RuntimeException("can't parse a json object of type " + theClass.getName() + " from ["
+ description + "]", e);
// LOG.warn("can't parse a json object from [" + description + "]", e);
// return null;
}
}
在此之后,我在 playframework 中得到以下异常
4664956 INFO [play-akka.actor.default-dispatcher-186] - resync sending states BE-beA ...
java.lang.IllegalArgumentException: Invalid type id 'eu.ec.dgempl.eessi.flow.AddSedToFlowControlMessage' (for id type 'Id.class'): no such class found
at org.codehaus.jackson.map.jsontype.impl.ClassNameIdResolver.typeFromId(ClassNameIdResolver.java:57)
at org.codehaus.jackson.map.jsontype.impl.TypeDeserializerBase._findDeserializer(TypeDeserializerBase.java:113)
at org.codehaus.jackson.map.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:82)
at org.codehaus.jackson.map.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:52)
at org.codehaus.jackson.map.deser.StdDeserializerProvider$WrappedDeserializer.deserialize(StdDeserializerProvider.java:461)
at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1286)
at org.codehaus.jackson.map.ObjectMapper.treeToValue(ObjectMapper.java:1733)
at eu.ec.dgempl.eessi.flow.impl.FlowServiceImpl.fromJson(FlowServiceImpl.java:167)
at eu.ec.dgempl.eessi.flow.impl.FlowServiceImpl.fromBody(FlowServiceImpl.java:144)
at eu.ec.dgempl.eessi.flow.impl.FlowServiceImpl.resync(FlowServiceImpl.java:130)
at controllers.Application.renderFlows(Application.java:796)
at controllers.Application.flows(Application.java:785)
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$22$$anonfun$apply$22.apply(routes_routing.scala:314)
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$22$$anonfun$apply$22.apply(routes_routing.scala:314)
at play.core.Router$HandlerInvoker$$anon$6$$anon$2.invocation(Router.scala:164)
at play.core.Router$Routes$$anon$1.invocation(Router.scala:345)
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:31)
at play.core.j.JavaAction$$anon$2.apply(JavaAction.scala:74)
at play.core.j.JavaAction$$anon$2.apply(JavaAction.scala:73)
at play.libs.F$Promise$PromiseActor.onReceive(F.java:420)
at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:159)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425)
at akka.actor.ActorCell.invoke(ActorCell.scala:386)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:230)
at akka.dispatch.Mailbox.run(Mailbox.scala:212)
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:502)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:262)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
4666398 INFO [pool-204-thread-1] - JAX-WS RI 2.2.4-b01: Stub for http://192.168.1.6:18003/cn/reliableTransport> execute Execute with delay=10 S :java.util.co