Comments (4)
I think I'm encountering this issue.
I want to parse the following:
val s = """{"event":"form","id":"xsD7n7h4rPem6pg0M1Bv19r","data":[{"name":"name","value":"Fred Bloggs"},{"name":"email","value":"[email protected]"}]}"""
Trying this with jerkson (com.codahale.jerkson.Json.parse(s)
) gives:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to scala.runtime.Nothing$
at .<init>(<console>:10)
at .<clinit>(<console>)
at .<init>(<console>:11)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:914)
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:546)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:577)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:543)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:694)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:745)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:651)
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:542)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:550)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:822)
at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:851)
at xsbt.ConsoleInterface.run(ConsoleInterface.scala:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:57)
at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:48)
at sbt.Console.console0$1(Console.scala:23)
at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:24)
at sbt.TrapExit$.executeMain$1(TrapExit.scala:33)
at sbt.TrapExit$$anon$1.run(TrapExit.scala:42)
However, using the twitter Json parser (com.twitter.json.Json.parse(s)
) correctly gives:
Map(event -> form, id -> xsD7n7h4rPem6pg0M1Bv19r, data -> List(Map(name -> name, value -> Fred Bloggs), Map(name -> email, value -> [email protected])))
from jerkson.
I have found that I can get most of the way with deserialising maps using:
Json.parse[Map[String, JValue]](json)
for a map between a String key and any kind of value. The resulting JValue needs post-processing but it's mostly useable. However, problems come up as soon as I have a JSON string containing the String or value "null". The above line then gives the error:
com.codahale.jerkson.ParsingException: Can not deserialize instance of com.codahale.jerkson.AST$JValue out of VALUE_NULL token
It seems that it doesn't support "null" as a valid JValue in this context.
from jerkson.
Okay, this isn't perfect, but with Coda's assistance I have discovered that Jerkson supports Option
types, so, in the above example:
Json.parse[Map[String, Option[JValue]]](json)
works nicely, but for a fuller explanation see my comment on another issue here: #41 (comment)
from jerkson.
What about fixing this? 8 months old...
from jerkson.
Related Issues (20)
- Parsing fails for Maps that contain unmarshalled keys HOT 2
- Support for parameterized types HOT 1
- Upgrade to Jackson 2 HOT 5
- ClassNotFoundException when parsing in sbt test HOT 4
- Build for Scala 2.9.2 HOT 1
- Huge List of Exceptions on generate()
- No update since 6 months. Jerkson is a dead end, isn't it? HOT 4
- Support dashes in json property names? HOT 2
- Unable to find a case accessor exception in test driver
- Add PrettyPrint (Pretty Please!)
- Release 0.6.0 HOT 2
- ClassNotFound Exception when deserializing using parallel collection HOT 1
- Exception with case classes nested within case classes HOT 5
- case class @JsonProperty ignored
- Can't parse case class with type-alias field HOT 1
- Jerkson does not Deserialize Immutable Map with Locale Key
- Parsing of case class with Strings starting with "{" fails
- Support for scala 2.10 HOT 7
- What's your proposed alternative to Jerkson HOT 4
- artifacts in Maven central
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jerkson.