-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
Collection of case classes deserialized as Collection of Map2 #650
Comments
Try this:
Jackson is a Java library based on Java Reflection. This approach is problematic due to Type Erasure. ClassTagExtensions uses Scala ClassTags to preserve more of the type information. |
This also seems to work:
The TypeReference is another way of preserving type information that would otherwise by lost to Type Erasure. |
Great! I assumed it was a type erasure issue. I had some issues trying ClassYagExtension that were unrelated to the immediate problem (probably build environment related). I'll give the Type Reference approach a try. |
Just reporting back, this doesn't actually pass it should "encode and decode consistently using class tag extension" in {
case class B(a: String, b: String)
val mapper = JsonMapper.builder().addModule(DefaultScalaModule).build() :: ClassTagExtensions
val data = List(B("a", "b"), B("c", "d"))
val s = mapper.writeValueAsString(data)
mapper.readValue[List[B]](s) shouldEqual data
} Produces the following failed test
But this one works..
Any idea why the first doesn't? I ran the example in a repl and it did seem to work. But not as a unit test. |
Any attempt to use the values throws a cast error. Unable to cast Map2 to B.
The text was updated successfully, but these errors were encountered: