-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
Case Classes with Option[Long] parameters don't deserialize properly #62
Comments
This uncovers one of the dirtier parts of Scala. The JVM doesn't support using an intrinsic like For 2.2, I've added patches to databind to support using class OptionLongHolder
{
@JsonDeserialize(contentAs=classOf[java.lang.Long])
var optLong: Option[Long]
} This works, as it forces Jackson to use Long for deserialization rather than the narrowest natural integer. |
We're currently tied to jackson 2.1.x. Is it somehow possible to get this backported? |
I'll look into it. AFAIK, core Jackson doesn't plan on any further maintenance on 2.1.x, but I'll see what I can do about an interim release. |
Ok, thanx! |
Hello, Just wanted to thank you for the fix in 2.2. Got a bit stressed when I noticed that conversion bug, so I was relieved to see that it's solved using the |
What is the workaround if your case class is generated for you? I don't have an access to apply attribute. |
@christophercurrie is it possible to create an optional module that uses what finatra has to work around this? It looks like they use the scala signature parsing https://github.com/twitter/finatra/tree/develop/jackson/src/main/scala/com/twitter/finatra/json/internal/caseclass/jackson Having to annotate works fine, but its problematic when you are trying to distribute a model class (for example) which now pulls in all of jackson databind. Had the annotation been in jackson-annotations it would be less problematic, but leaking a dependency like that really sucks. I'd be really open to having a separate module (if we don't want to include that in the main one) that provided for option[long] parsing via signature parsing in the interim, until the deprecation comes around for 2.10> |
# 🔍 Description ## Issue References 🔗 This pull request fixes #6476 : spark historyserver -> Show incomplete applications -> kyuubi query engine ui error(java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long). The reason: it's related to FasterXML/jackson-module-scala#62 ## Describe Your Solution 🔧 add JsonDeserialize(contentAs = classOf[java.lang.Long]) annotation ## Types of changes 🔖 - [x] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan 🧪 #### Behavior Without This Pull Request ⚰️ #### Behavior With This Pull Request 🎉 #### Related Unit Tests --- # Checklist 📝 - [x] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) **Be nice. Be informative.** Closes #6479 from felixzh2020/issues/6476. Closes #6476 034bfe5 [felixzh] [KYUUBI #6476] spark historyserver Show incomplete applications kyuubi query engine ui error b7b0db2 [felixzh] [KYUUBI #6476] spark historyserver Show incomplete applications kyuubi query engine ui error a66163a [felixzh] [KYUUBI #6476] spark historyserver Show incomplete applications kyuubi query engine ui error Authored-by: felixzh <felixzh2020@126.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
# 🔍 Description ## Issue References 🔗 This pull request fixes #6476 : spark historyserver -> Show incomplete applications -> kyuubi query engine ui error(java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long). The reason: it's related to FasterXML/jackson-module-scala#62 ## Describe Your Solution 🔧 add JsonDeserialize(contentAs = classOf[java.lang.Long]) annotation ## Types of changes 🔖 - [x] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan 🧪 #### Behavior Without This Pull Request ⚰️ #### Behavior With This Pull Request 🎉 #### Related Unit Tests --- # Checklist 📝 - [x] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) **Be nice. Be informative.** Closes #6479 from felixzh2020/issues/6476. Closes #6476 034bfe5 [felixzh] [KYUUBI #6476] spark historyserver Show incomplete applications kyuubi query engine ui error b7b0db2 [felixzh] [KYUUBI #6476] spark historyserver Show incomplete applications kyuubi query engine ui error a66163a [felixzh] [KYUUBI #6476] spark historyserver Show incomplete applications kyuubi query engine ui error Authored-by: felixzh <felixzh2020@126.com> Signed-off-by: Cheng Pan <chengpan@apache.org> (cherry picked from commit c6f2ca2) Signed-off-by: Cheng Pan <chengpan@apache.org>
It seems that for small numbers, an Option[Long] in a case class actually gets deserialized with a runtime type of int. This can then manifest in a couple ways. Maps using these values as keys may not behave as expected, and conversions to Java Longs will throw a ClassCastException:
This only seems to affect case classes. Option[Long] by itself seems to behave correctly.
The text was updated successfully, but these errors were encountered: