-
-
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
Context attributes are not passed/available to custom serializer if object is in POJO #1991
Comments
Version 2.9.5 |
Thank you for reporting this. I agree in that context should be retained and attributes available. There may be technical problems in achieving that with 2.x since there is unfortunately no way to pass them through methods in But I hope to see if there might something simple to do; it really depends on how delegation works for |
A hack that worked for me is to use
In the custom serializer, you can get hold of the context through the Writer
And use it as below
|
@SrinivasKothuri Thank you for sharing this interesting technique! Yes, that allows passing of information. :) |
Below is a test case where I create a custom serializer and use it to serialize an object 1) in a HashMap and 2) in an ObjectNode. In both cases I pass attribute to the serializer like this:
mapper.writer().withAttribute("myAttr", "Hello!")
Serializing HashMap works as expected, but during ObjectNode serialization the attribute is null . It seems that in both cases the custom serializer should get access to the passed attribute and so both lines in the output should contain "Hello!"
Produced output from running testCase.test()
Test case:
The text was updated successfully, but these errors were encountered: