-
-
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
Map key converted to byte array is not serialized as base64 string #1552
Comments
This may actually be a combination of multiple problems. One problem would be that there may not (yet) be a key serializer for type Beyond this challenge there may actually be another problem: Java Type Erasure. In your case you are effectively serializing I mention this second problem for sake of completeness, as it is not really specific for this particular problem; but it may require minor other change. class BinaryKeyMap<V> extends HashMap<byte[], T> { } which binds key type (and if you want, value type too of course) and is NOT subject to Java Type Erasure (since type information is stored in class/sub-class relationship -- there's longer explanation but I digress). Anyway: I will consider problem (1) now. |
Can someone please tell me how to stop jackson from serializing byte arrays to base64 string |
@plokhotnyuk Any java implementation? I have been trying but having some troubles with native |
@kishor-p class of But as to not serializing as base64: what would you prefer? Array of numbers? I think there is a |
The use case concerns X500Principal (aka "distinguished name") which can be mapped from/to byte array using a mixin class. Jackson serializes byte arrays as base64 strings by default. However, this failes when X500Principal is used as a Map key. In that case, the resulting byte array is serialized using toString(), which yields a useless output.
Complete example:
This outputs
{"[B@1753acfe":"MA8xDTALBgNVBAMTBEpvaG4="}
. The value is correctly serialized as a base64 string, but the key isn't. I tested this with 2.8.6, 2.8.7 and 2.9.0.pr1. I haven't tested deserialization so far.(Note that X500Principal cannot, in general, be serialized in its string representation (i.e., as per getName() and the String constructor), because the byte representation is the authoritative one and doesn't round-trip through the string representation in the general case. Therefore a serialization based on the byte array is necessary.)
The text was updated successfully, but these errors were encountered: