Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialization of Collection in Inner Class fails with ClassCastException #364

Open
saurabheights opened this issue Nov 25, 2016 · 0 comments

Comments

@saurabheights
Copy link

saurabheights commented Nov 25, 2016

Hi,
I am facing this issue where I need to deserialize a Map of Integer and Pair of Strings, but this leads to ClassCastException. The code works fine with Jackson, but fails at boon. Migrating to jackson is not an option as the whole plethora of code used to serialize this class(which is humungous, in fact) is intermingled with boon and thus I am in a bind. I am using boon 0.34. Any help is appreciated.

public static class C {
    //ModifiablePair implements Serializable and has get/set to access/modify a pair of objects.
    public Map<Integer, ModifiablePair<String, String>> a = new HashMap<>();
}

public static void main() {
    try {
        String serializedJson = "{\"a\":{}}";
        Logger.info(new com.fasterxml.jackson.databind.ObjectMapper().writeValueAsString(new C()));
        C c = new com.fasterxml.jackson.databind.ObjectMapper().readValue(serializedJson, C.class);
        Logger.info(String.valueOf(c.a));
    } catch (Exception ex) {
        Logger.error("First Method failed.", ex);
    }
    try {
        String serializedJson = "{\"a\":{}}";
        ObjectMapper mapper = JsonFactory.create();
        C c = mapper.fromJson(serializedJson, C.class);
        Logger.info(String.valueOf(c.a));
    } catch (Exception ex) {
        Logger.error("Second Method failed.", ex);
    }
}

The stacktrace is long but here it is:-

2016-11-26 00:57:19,393 - play-akka.actor.default-dispatcher-6 [INFO] - {"a":{}}

2016-11-26 00:57:19,397 - play-akka.actor.default-dispatcher-6 [INFO] - {}

2016-11-26 00:57:19,424 - play-akka.actor.default-dispatcher-6 [ERROR] - Second Method failed.
org.boon.Exceptions$SoftenedException: fieldName a of class class controllers.Application$C had issues for value MAP for field FieldInfo [name=a, type=interface java.util.Map, parentType=class controllers.Application$C]

 CAUSE java.lang.ClassCastException :: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
    at org.boon.core.reflection.MapperSimple.fromValueMapHandleValueCase(MapperSimple.java:1240) ~[boon-0.32.jar:0.32]
    at org.boon.core.reflection.MapperSimple.fromValueMap(MapperSimple.java:1134) ~[boon-0.32.jar:0.32]
    at org.boon.json.JsonMappingParser.finalExtract(JsonMappingParser.java:208) ~[boon-0.32.jar:0.32]
    at org.boon.json.JsonMappingParser.parse(JsonMappingParser.java:200) ~[boon-0.32.jar:0.32]
    at org.boon.json.implementation.ObjectMapperImpl.readValue(ObjectMapperImpl.java:67) ~[boon-0.32.jar:0.32]
    at org.boon.json.implementation.ObjectMapperImpl.fromJson(ObjectMapperImpl.java:278) ~[boon-0.32.jar:0.32]
    at controllers.Application.getStatus(Application.java:131) ~[classes/:na]
    at Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(routes_routing.scala:201) [classes/:na]
    at Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(routes_routing.scala:201) [classes/:na]
    at play.core.Router$HandlerInvoker$$anon$7$$anon$2.invocation(Router.scala:183) [play_2.10.jar:2.2.0]
    at play.core.Router$Routes$$anon$1.invocation(Router.scala:377) [play_2.10.jar:2.2.0]
    at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:56) [play_2.10.jar:2.2.0]
    at play.GlobalSettings$1.call(GlobalSettings.java:64) [play_2.10.jar:2.2.0]
    at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:91) [play_2.10.jar:2.2.0]
    at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:90) [play_2.10.jar:2.2.0]
    at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82) [play_2.10.jar:2.2.0]
    at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82) [play_2.10.jar:2.2.0]
    at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:251) [scala-library-2.10.3.jar:na]
    at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:249) [scala-library-2.10.3.jar:na]
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library-2.10.3.jar:na]
    at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:37) [play_2.10.jar:2.2.0]
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42) [akka-actor_2.10.jar:2.2.0]
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386) [akka-actor_2.10.jar:2.2.0]
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.10.3.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.10.3.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.10.3.jar:na]
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.10.3.jar:na]
    at org.boon.Exceptions.handle(Exceptions.java:128) ~[boon-0.32.jar:0.32]
    at org.boon.core.reflection.MapperSimple.fromValueMap(MapperSimple.java:1139) ~[boon-0.32.jar:0.32]
    at org.boon.json.JsonMappingParser.finalExtract(JsonMappingParser.java:208) ~[boon-0.32.jar:0.32]
    at org.boon.json.JsonMappingParser.parse(JsonMappingParser.java:200) ~[boon-0.32.jar:0.32]
    at org.boon.json.implementation.ObjectMapperImpl.readValue(ObjectMapperImpl.java:67) ~[boon-0.32.jar:0.32]
    at org.boon.json.implementation.ObjectMapperImpl.fromJson(ObjectMapperImpl.java:278) ~[boon-0.32.jar:0.32]
    at controllers.Application.getStatus(Application.java:131) ~[classes/:na]
    at Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(routes_routing.scala:201) [classes/:na]
    at Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(routes_routing.scala:201) [classes/:na]
    at play.core.Router$HandlerInvoker$$anon$7$$anon$2.invocation(Router.scala:183) [play_2.10.jar:2.2.0]
    at play.core.Router$Routes$$anon$1.invocation(Router.scala:377) [play_2.10.jar:2.2.0]
    at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:56) [play_2.10.jar:2.2.0]
    at play.GlobalSettings$1.call(GlobalSettings.java:64) [play_2.10.jar:2.2.0]
    at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:91) [play_2.10.jar:2.2.0]
    at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:90) [play_2.10.jar:2.2.0]
    at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82) [play_2.10.jar:2.2.0]
    at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82) [play_2.10.jar:2.2.0]
    at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:251) [scala-library-2.10.3.jar:na]
    at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:249) [scala-library-2.10.3.jar:na]
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library-2.10.3.jar:na]
    at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:37) [play_2.10.jar:2.2.0]
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42) [akka-actor_2.10.jar:2.2.0]
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386) [akka-actor_2.10.jar:2.2.0]
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.10.3.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.10.3.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.10.3.jar:na]
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.10.3.jar:na]
Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
    at org.boon.core.reflection.MapperSimple.fromValueMapHandleValueCase(MapperSimple.java:1240) ~[boon-0.32.jar:0.32]
    at org.boon.core.reflection.MapperSimple.fromValueMap(MapperSimple.java:1134) ~[boon-0.32.jar:0.32]
    ... 25 common frames omitted

P.S.: I searched previous issues but found nothing so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant