Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

akka-http-jackson unable to unmarshall JSON array? #165

Closed
george-ball opened this issue Aug 9, 2017 · 1 comment · Fixed by #170
Closed

akka-http-jackson unable to unmarshall JSON array? #165

george-ball opened this issue Aug 9, 2017 · 1 comment · Fixed by #170

Comments

@george-ball
Copy link

I have a simple program (inspired by a sample from another blog) that receives data to a POST request at JSON, and works fine when I use the json4s variant. However when I run the same requests into a version of the app that uses the Hakka-http-json I see an unmarshalling exception when unmarshalling a JSON array.
I'd expect equivalent behaviour in both examples, so I suspect something is missing in either my code, documentation, or elsewhere?

Json4s:
$ curl -X POST -H 'Content-Type: application/json' -d '[{"name": "Julie-ann", "age": 21}, {"name": "George", "age": 22}]' http://localhost:8080/customers
"Added 2 customers\n
$ curl http://localhost:8080/customers
[{"name":"Julie-ann","age":21},{"name":"George","age":22}]

Jackson:
$ curl -X POST -H 'Content-Type: application/json' -d '[{"name": "Julie-ann", "age": 21}, {"name": "George", "age": 22}]' http://localhost:8080/customers
There was an internal server error

Server:
[info] Running com.example.JacksonHttpApp
Press RETURN to stop...
[INFO] [08/09/2017 15:54:40.459] [JacksonHttpApp-akka.actor.default-dispatcher-3] [akka.actor.ActorSystemImpl(JacksonHttpApp)] Server online at http://localhost:8080/
[ERROR] [08/09/2017 15:54:44.851] [JacksonHttpApp-akka.actor.default-dispatcher-6] [akka.actor.ActorSystemImpl(JacksonHttpApp)] Error during processing of request: 'scala.collection.immutable.Map$Map2 cannot be cast to com.example.JacksonHttpApp$Customer'. Completing with 500 Internal Server Error response. To change default exception handling behavior, provide a custom ExceptionHandler.
java.lang.ClassCastException: scala.collection.immutable.Map$Map2 cannot be cast to com.example.JacksonHttpApp$Customer
at scala.collection.immutable.List.foreach(List.scala:389)
at com.example.JacksonHttpApp$.$anonfun$routes$4(AkkaJacksonParsing.scala:27)
at akka.http.scaladsl.server.directives.RouteDirectives.$anonfun$complete$1(RouteDirectives.scala:47)
...

Progs attached here...
progs.zip

@hseeberger
Copy link
Owner

Thanks for reporting. Could you please set up a GitHub repo with the two variants?

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

Successfully merging a pull request may close this issue.

2 participants