-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support for BCP 47 java.util.Locale
serialization/deserialization
#3259
Comments
Sounds like we have sub-optimal behavior; would be great to improve handling. I think this is something that might be relatively easy to support so marking as "good first issue". |
@cowtowncoder Thanks for responding to this issue. Would it be a good idea to create a separate |
I often recommend new modules for additions, but in this case it seems like bit of an overkill, if it only affects handling of one JDK class. Especially if it was possible to address this wrt all users in core |
@cowtowncoder , Can I pick this up? Looks like we need to write custom serializer/de-serializer for java.util.Locale class |
@praneethjreddy Sure. I do think we have custom (de)serializer already, but it might be part of a multi-type (de)serializer... let me look. Ok, so:
So, it may be necessary to have separate serializer implementation if deserializer-only handling can not be made to work. |
CLA received for the PR; hoping to review and merge the fix RSN! |
java.util.Locale
serialization/deserialization
Uhhhh. Should have remember to link #1600 here; Jackson 3.0 already serializes using "toLanguageTag()". So 3.0 ( |
Can someone clarify exactly what came out of this? Are you saying that for language tag serialization we need to create our own custom serializer for |
@garretwilson At this point I think full answer would require going through changes including #3265 but your assessment sounds correct. As far as I can see, |
@cowtowncoder thanks for the confirmation. This lopsided implementation of RFC 5646 (the latest language tag RFC for BCP 47) is less than ideal. Language tags are a core identifier. Furthermore there is no reason to use the outdated As someone already suggested, there should be a module that serializes and deserializes
However in this case the alternative is much, much worse than having a module with just a single class in it—we force the developer to implement This also brings up the fact that there doesn't seem to be a simple way to create a to-string serializer using some other method. (Nor for serializers; see #4004.) Overwriting an abstract class for such a simple use case is much too verbose. I'll be happy to do this, along with #4004. I propose to:
Obviously I can just write these and publish them in my own library, but these use cases are by no means esoteric—this seems to me to be bread-and-butter utilities almost everyone would need. It seems better all around if this were included in Jackson. |
Ok, some notes:
|
Fair enough.
I'll have a better idea of which what best once I start implementing it.
Not "strongly couple", but I just suspect that once the configurable to/from string utilities are in place, they will be so nice that they will be an obvious choice. So without making you sign on the dotted line for the specific implementation details, the thing I want to get to here is whether you're open to reviewing and accepting these conceptually. If so, I propose the following:
Do those sound like reasonable next steps? |
@garretwilson Apologies for slow follow-up. Yes, those sound like good next steps. |
Related to this issue, I just discovered that even if I install a custom serializer for On top of that, it turns out the key serializer, even though it is an implementation of I'll leave discussion of that design for elsewhere, but here I think it goes to show that at the very least Jackson needs a separate module for |
@garretwilson Yes, the division between Value and Key serializers/deserializers is unfortunate, but not easily removable -- partly since In hindsight I suppose |
Describe the bug
Locale with BCP 47 extensions are not serialized / de-serialized as expected using
ObjectMapper
.Version information
Which Jackson version(s) was this for?
All Jackson versions.
To Reproduce
If you have a way to reproduce this with:
Brief code sample/snippet: include here in pre-formatted/code section
Longer example stored somewhere else (diff repo, snippet), add a link
N/A. Reproducible with the above piece of code.
Textual explanation:
forLanguageTag
locale is used to create a locale object from a BCP 47 compliant locale string. Thex-debug
gets added as extensions in the Locale.toString()
method of locale to convert it to String.toLanguageTag()
andforLanguageTag()
instead to convert to / from String.x-debug
gets added as a Variant instead of extensions, which is not expected.Expected behavior
Additional Details
The text was updated successfully, but these errors were encountered: