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

Argonaut Json parser causes ClassCastException #157

Closed
julien-truffaut opened this issue Dec 29, 2014 · 8 comments
Closed

Argonaut Json parser causes ClassCastException #157

julien-truffaut opened this issue Dec 29, 2014 · 8 comments
Labels
bug

Comments

@julien-truffaut
Copy link
Member

@julien-truffaut julien-truffaut commented Dec 29, 2014

I wrote 2 EntityDecoder, one using ArgonautSupport.json and one using argonaut.Parse. The latter is working but the first one generates the following error: java.lang.ClassCastException: scala.Some cannot be cast to argonaut.Json

def jsonEntityDecoder[A](implicit ev: DecodeJson[A]): EntityDecoder[A] =
    ArgonautSupport.json.map(json =>
      ev.decodeJson(json).fold(
        (message, history) => sys.error(s"Could not decode json $json, error: $message, cursor: $history"),
        identity
      )
    )

  def jsonEntityDecoder2[A](implicit ev: DecodeJson[A]): EntityDecoder[A] =
    EntityDecoder.decodeBy(MediaType.`application/json`){msg =>
      org.http4s.DecodeResult.apply(EntityDecoder.decodeString(msg).map{s =>
        Parse.parse(s).fold(
          m => ParseResult.fail(s"Cannot parse string $s into json, error: $m"),
          ParseResult.success
        ).flatMap(json =>
          ev.decodeJson(json).fold(
            (m, h) => ParseResult.fail(s"Cannot parse json $json, error: $m $h"),
            ParseResult.success
          )
        )
      })
    }

I am sure we can reproduce the error without DecodeJson but I didn't have the time to do so

@julien-truffaut julien-truffaut added the bug label Dec 29, 2014
@julien-truffaut julien-truffaut changed the title Argonaut Json parser generates ClassCastException Argonaut Json parser causes ClassCastException Dec 29, 2014
@bryce-anderson
Copy link
Member

@bryce-anderson bryce-anderson commented Dec 29, 2014

A stack trace would be useful in diagnosing this; could you post it?

@julien-truffaut
Copy link
Member Author

@julien-truffaut julien-truffaut commented Dec 30, 2014

sure

java.lang.ClassCastException: scala.Some cannot be cast to argonaut.Json
    at jawn.support.argonaut.Parser$$anon$1.jint(Parser.scala:14)
    at jawn.support.argonaut.Parser$$anon$1.jint(Parser.scala:9)
    at jawn.Parser$class.parseNum(Parser.scala:163)
    at jawn.AsyncParser.parseNum(AsyncParser.scala:60)
    at jawn.Parser$class.rparse(Parser.scala:343)
    at jawn.AsyncParser.rparse(AsyncParser.scala:60)
    at jawn.AsyncParser.churn(AsyncParser.scala:213)
    at jawn.AsyncParser.finish(AsyncParser.scala:98)
    at jawnstreamz.package$$anonfun$parseJson$1$$anonfun$apply$2.apply(package.scala:31)
    at jawnstreamz.package$$anonfun$parseJson$1$$anonfun$apply$2.apply(package.scala:31)
    at scalaz.stream.Process$$anonfun$onComplete$1.apply(Process.scala:331)
    at scalaz.stream.Process$$anonfun$onComplete$1.apply(Process.scala:331)
    at scalaz.stream.Process$$anonfun$1$$anonfun$apply$3$$anonfun$apply$4.apply(Process.scala:106)
    at scalaz.stream.Process$$anonfun$1$$anonfun$apply$3$$anonfun$apply$4.apply(Process.scala:106)
    at scalaz.stream.Util$.Try(Util.scala:42)
    at scalaz.stream.Process$$anonfun$1$$anonfun$apply$3.apply(Process.scala:106)
    at scalaz.stream.Process$$anonfun$1$$anonfun$apply$3.apply(Process.scala:106)
    at scalaz.Trampoline$$anonfun$delay$1.apply(Free.scala:234)
    at scalaz.Trampoline$$anonfun$delay$1.apply(Free.scala:234)
    at scalaz.Free$$anonfun$run$1.apply(Free.scala:172)
    at scalaz.Free$$anonfun$run$1.apply(Free.scala:172)
    at scalaz.Free.go2$1(Free.scala:119)
    at scalaz.Free.go(Free.scala:122)
    at scalaz.Free.run(Free.scala:172)
    at scalaz.stream.Process$$anonfun$go$1$1.apply(Process.scala:75)
    at scalaz.stream.Process$$anonfun$go$1$1.apply(Process.scala:75)
    at scalaz.stream.Util$.Try(Util.scala:42)
    at scalaz.stream.Process$class.go$1(Process.scala:75)
    at scalaz.stream.Process$class.step(Process.scala:88)
    at scalaz.stream.Process$Append.step(Process.scala:611)
    at scalaz.stream.Process$$anonfun$suspendStep$1.apply(Process.scala:97)
    at scalaz.stream.Process$$anonfun$suspendStep$1.apply(Process.scala:96)
    at scalaz.stream.Process$$anonfun$1$$anonfun$apply$3$$anonfun$apply$4.apply(Process.scala:106)
    at scalaz.stream.Process$$anonfun$1$$anonfun$apply$3$$anonfun$apply$4.apply(Process.scala:106)
    at scalaz.stream.Util$.Try(Util.scala:42)
    at scalaz.stream.Process$$anonfun$1$$anonfun$apply$3.apply(Process.scala:106)
    at scalaz.stream.Process$$anonfun$1$$anonfun$apply$3.apply(Process.scala:106)
    at scalaz.Trampoline$$anonfun$delay$1.apply(Free.scala:234)
    at scalaz.Trampoline$$anonfun$delay$1.apply(Free.scala:234)
    at scalaz.std.FunctionInstances$$anon$1$$anonfun$map$1.apply(Function.scala:56)
    at scalaz.Free$$anonfun$run$1.apply(Free.scala:172)
    at scalaz.Free$$anonfun$run$1.apply(Free.scala:172)
    at scalaz.Free.go2$1(Free.scala:119)
    at scalaz.Free.go(Free.scala:122)
    at scalaz.Free.run(Free.scala:172)
    at scalaz.stream.Process$$anonfun$go$1$1.apply(Process.scala:75)
    at scalaz.stream.Process$$anonfun$go$1$1.apply(Process.scala:75)
    at scalaz.stream.Util$.Try(Util.scala:42)
    at scalaz.stream.Process$class.go$1(Process.scala:75)
    at scalaz.stream.Process$class.step(Process.scala:88)
    at scalaz.stream.Process$Append.step(Process.scala:611)
    at scalaz.stream.Process$$anonfun$pipe$1.apply(Process.scala:134)
    at scalaz.stream.Process$$anonfun$pipe$1.apply(Process.scala:130)
    at scalaz.stream.Process$$anonfun$flatMap$1.apply(Process.scala:40)
    at scalaz.stream.Process$$anonfun$flatMap$1.apply(Process.scala:40)
    at scalaz.stream.Util$.Try(Util.scala:42)
    at scalaz.stream.Process$class.flatMap(Process.scala:40)
    at scalaz.stream.Process$Emit.flatMap(Process.scala:571)
    at scalaz.stream.Process$$anonfun$flatMap$4.apply(Process.scala:42)
    at scalaz.stream.Process$$anonfun$flatMap$4.apply(Process.scala:42)
    at scalaz.Free$$anonfun$map$1.apply(Free.scala:52)
    at scalaz.Free$$anonfun$map$1.apply(Free.scala:52)
    at scalaz.Free.resume(Free.scala:73)
    at scalaz.Free.go2$1(Free.scala:118)
    at scalaz.Free.go(Free.scala:122)
    at scalaz.Free.run(Free.scala:172)
    at scalaz.stream.Process$$anonfun$go$1$1.apply(Process.scala:75)
    at scalaz.stream.Process$$anonfun$go$1$1.apply(Process.scala:75)
    at scalaz.stream.Util$.Try(Util.scala:42)
    at scalaz.stream.Process$class.go$1(Process.scala:75)
    at scalaz.stream.Process$class.step(Process.scala:88)
    at scalaz.stream.Process$Append.step(Process.scala:611)
    at scalaz.stream.Process$class.go$3(Process.scala:464)
    at scalaz.stream.Process$$anonfun$go$3$3.apply(Process.scala:473)
    at scalaz.stream.Process$$anonfun$go$3$3.apply(Process.scala:472)
    at scalaz.concurrent.Task$$anonfun$flatMap$1$$anonfun$1.apply(Task.scala:36)
    at scalaz.concurrent.Task$$anonfun$flatMap$1$$anonfun$1.apply(Task.scala:36)
    at scalaz.concurrent.Task$.Try(Task.scala:379)
    at scalaz.concurrent.Task$$anonfun$flatMap$1.apply(Task.scala:36)
    at scalaz.concurrent.Task$$anonfun$flatMap$1.apply(Task.scala:34)
    at scalaz.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:59)
    at scalaz.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:59)
    at scalaz.concurrent.Future.step(Future.scala:111)
    at scalaz.concurrent.Future.listen(Future.scala:76)
    at scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80)
    at scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80)
    at scalaz.Free$$anonfun$map$1.apply(Free.scala:52)
    at scalaz.Free$$anonfun$map$1.apply(Free.scala:52)
    at scalaz.Free.resume(Free.scala:73)
    at scalaz.Free.go2$1(Free.scala:118)
    at scalaz.Free.go(Free.scala:122)
    at scalaz.Free.run(Free.scala:172)
    at scalaz.concurrent.Future$$anonfun$async$1$$anonfun$apply$14.apply(Future.scala:363)
    at scalaz.concurrent.Future$$anonfun$async$1$$anonfun$apply$14.apply(Future.scala:363)
    at org.http4s.blaze.Http1Stage$$anonfun$1.org$http4s$blaze$Http1Stage$class$$anonfun$$go$1(Http1Stage.scala:136)
    at org.http4s.blaze.Http1Stage$$anonfun$1.apply(Http1Stage.scala:154)
    at org.http4s.blaze.Http1Stage$$anonfun$1.apply(Http1Stage.scala:131)
    at scalaz.concurrent.Future$$anonfun$async$1.apply(Future.scala:363)
    at scalaz.concurrent.Future$$anonfun$async$1.apply(Future.scala:363)
    at scalaz.concurrent.Future.listen(Future.scala:80)
    at scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80)
    at scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80)
    at scalaz.Free$$anonfun$map$1.apply(Free.scala:52)
    at scalaz.Free$$anonfun$map$1.apply(Free.scala:52)
    at scalaz.Free.resume(Free.scala:73)
    at scalaz.Free.go2$1(Free.scala:118)
    at scalaz.Free.go(Free.scala:122)
    at scalaz.Free.run(Free.scala:172)
    at scalaz.concurrent.Future$$anonfun$async$1$$anonfun$apply$14.apply(Future.scala:363)
    at scalaz.concurrent.Future$$anonfun$async$1$$anonfun$apply$14.apply(Future.scala:363)
    at org.http4s.client.blaze.BlazeClient$$anonfun$prepare$1$$anonfun$org$http4s$client$blaze$BlazeClient$class$$anonfun$$tryClient$1$1.apply(BlazeClient.scala:46)
    at org.http4s.client.blaze.BlazeClient$$anonfun$prepare$1$$anonfun$org$http4s$client$blaze$BlazeClient$class$$anonfun$$tryClient$1$1.apply(BlazeClient.scala:38)
    at scalaz.concurrent.Future$$anonfun$runAsync$1.apply(Future.scala:143)
    at scalaz.concurrent.Future$$anonfun$runAsync$1.apply(Future.scala:143)
    at scalaz.concurrent.Future$$anonfun$async$1$$anonfun$apply$14.apply(Future.scala:363)
    at scalaz.concurrent.Future$$anonfun$async$1$$anonfun$apply$14.apply(Future.scala:363)
    at scalaz.concurrent.Future$$anonfun$runAsync$1.apply(Future.scala:143)
    at scalaz.concurrent.Future$$anonfun$runAsync$1.apply(Future.scala:143)
    at scalaz.concurrent.Future$$anonfun$async$1$$anonfun$apply$14.apply(Future.scala:363)
    at scalaz.concurrent.Future$$anonfun$async$1$$anonfun$apply$14.apply(Future.scala:363)
    at org.http4s.client.blaze.Http1ClientReceiver.org$http4s$client$blaze$Http1ClientReceiver$$requestLoop(Http1ClientReceiver.scala:102)
    at org.http4s.client.blaze.Http1ClientReceiver$$anonfun$readAndParse$1.apply(Http1ClientReceiver.scala:69)
    at org.http4s.client.blaze.Http1ClientReceiver$$anonfun$readAndParse$1.apply(Http1ClientReceiver.scala:68)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

@bryce-anderson
Copy link
Member

@bryce-anderson bryce-anderson commented Dec 30, 2014

I think we have classpath problems. We depend on argonaut 6.1-M5 and jawn depends on 6.0.4.

The stacktrace points to here which unfortunately doesn't include a full type signature, but should be of type Json. Unfortunately the type signature changed from Double => Json in argonaut 6.0.4 to Double => Option[Json] in 6.1-M5. This is probably your class cast exception.

I tried dropping our argonaut dep in the build and hoping to just pull it in with jawn, but I get other classpath related issues such as java.lang.IncompatibleClassChangeError: Found class scalaz.IndexedStoreT, but interface was expected which is almost certainly due to the migration of argonaut from scalaz 7.0.6 to 7.1.0.

So braking changes suck, but this isn't a problem we can fix in http4s; bummer. Someone could ask jawn for a new release?

@rossabaker
Copy link
Member

@rossabaker rossabaker commented Dec 30, 2014

Worst case, I should be able to republish an upgraded argonaut-support against the current jawn release, but let's see what Erik wants to do on the ticket above.

@rossabaker
Copy link
Member

@rossabaker rossabaker commented Dec 30, 2014

After typelevel/jawn#23 is released, we can fix this with an upgrade.

@rossabaker
Copy link
Member

@rossabaker rossabaker commented Jan 2, 2015

Fix released as v0.5.2, on its way to Maven Central.

@rossabaker rossabaker closed this Jan 2, 2015
@julien-truffaut
Copy link
Member Author

@julien-truffaut julien-truffaut commented Jan 2, 2015

thanks @rossabaker

rossabaker added a commit that referenced this issue Jan 5, 2015
Really fixes #157
@rossabaker
Copy link
Member

@rossabaker rossabaker commented Jan 5, 2015

Released v0.5.3 with the above commit.

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

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.