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

Missing support of parsing immutable.IntMap and mutable.LongMap #593

Closed
plokhotnyuk opened this issue Aug 18, 2022 · 8 comments
Closed

Missing support of parsing immutable.IntMap and mutable.LongMap #593

plokhotnyuk opened this issue Aug 18, 2022 · 8 comments
Labels

Comments

@plokhotnyuk
Copy link

In case of parsing jackson-module-scala throws java.lang.IllegalArgumentException: Need exactly 2 type parameters for map like types while serialization works as expected.

@pjfanning
Copy link
Member

Thanks for reporting this. I've added tests for serialization - IntMap/LongMap were not tested anywhere in the test suite.

Adding a fix for deserialization might be tricky - based on how the code currently works. When I recently added BitSet deserialization support, the solution was quite hacky.

@cowtowncoder
Copy link
Member

I don't have much context or anything, but I think Scala module already creates MapLikeTypes for other Map-like (but not implementing java.util.Map) types with custom TypeModifier. So the specific symptom can possibly be fixed without too much trouble assuming modifier can easily know/detect both key and value types (instead of having to point to Class that has 2 type parameters).

@pjfanning pjfanning added the 2.14 label Aug 20, 2022
@pjfanning
Copy link
Member

I have got basic support merged to 2.14 branch now. There are shortcomings for types like IntMap[Long] as the code the inner type (Long) is erased by the time Jackson's Java reflection based code gets to introspect it. I'll come back to that later.

@plokhotnyuk
Copy link
Author

I tried with the latest snapshot version and got following errors:

[info]   com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `scala.collection.mutable.LongMap<boolean>` from Object value (token `JsonToken.START_OBJECT`)
[info]  at [Source: (byte[])"{"-900845381675988":true,"-654142214247":false,"-45042269083799408":true,"-407439046":true,"4934063348569":true,"2467031674284864":false,"4298364401":true,"7401095022":false,"-20371952340950":false,"697125858266480539":false}"; line: 1, column: 1]
[info]   at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
[info]   at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1746)
[info]   at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1520)
[info]   at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1467)
[info]   at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.handleNonArray(CollectionDeserializer.java:396)
[info]   at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:252)
[info]   at com.fasterxml.jackson.module.scala.deser.GenericFactoryDeserializerResolver$Deserializer.deserialize(GenericFactoryDeserializerResolver.scala:125)
[info]   at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)
[info]   at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4697)
[info]   at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3746)
[info]   at com.fasterxml.jackson.module.scala.ClassTagExtensions.readValue(ClassTagExtensions.scala:147)
[info]   at com.fasterxml.jackson.module.scala.ClassTagExtensions.readValue$(ClassTagExtensions.scala:146)
[info]   com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `scala.collection.immutable.IntMap<boolean>` from Object value (token `JsonToken.START_OBJECT`)
[info]  at [Source: (byte[])"{"0":false,"190":false,"402":true,"169992":true,"201204":false,"149872405":false,"2102338642":true,"-12975191":true,"-10963":false,"-8":true}"; line: 1, column: 1]
[info]   at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
[info]   at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1746)
[info]   at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1520)
[info]   at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1467)
[info]   at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.handleNonArray(CollectionDeserializer.java:396)
[info]   at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:252)
[info]   at com.fasterxml.jackson.module.scala.deser.GenericFactoryDeserializerResolver$Deserializer.deserialize(GenericFactoryDeserializerResolver.scala:125)
[info]   at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)
[info]   at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4697)
[info]   at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3746)
[info]   at com.fasterxml.jackson.module.scala.ClassTagExtensions.readValue(ClassTagExtensions.scala:147)
[info]   at com.fasterxml.jackson.module.scala.ClassTagExtensions.readValue$(ClassTagExtensions.scala:146)

@pjfanning
Copy link
Member

Thanks for checking @plokhotnyuk

Could you try jacksonMapper.readValue(jsonBytes, new TypeReference[IntMap[Boolean]] {}) instead of jacksonMapper.readValue[IntMap[Boolean]](jsonBytes)? This change seems to work for me. I'll look into why the other form fails.

@pjfanning
Copy link
Member

@plokhotnyuk I think I've fixed the issue with ClassTagExtensions - the readValue[IntMap[Boolean]](jsonBytes) function should now be ok.

@plokhotnyuk
Copy link
Author

@pjfanning Thanks a lot! Both approaches works for me in the latest snapshot.

@cowtowncoder Could you please cut a milestone version for 2.14 branch of Jackson?

@cowtowncoder
Copy link
Member

@plokhotnyuk I am hoping to close issues to be able to do that but cannot really promise a concrete day. I suspect 2.14.0-rc1 will get out sometime early September.

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

No branches or pull requests

3 participants