-
-
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
ObjectMapper serializes CharSequence
subtypes as POJO instead of as String (JDK 15+)
#3305
Comments
That sounds like a regression and has occasionally happened with at least one other JDK type (maybe Need to figure out a way to avoid this -- but it can be rather nasty one to figure out, given that |
Hi I worked around the problem by forcing any class that implements CharSequence to use ToStringSerializer. I added the serializer to the ObjectMapper :
I'm not 100% convinced about this solution, as I may have a genuine Bean class that implements CharSequence. I did not want to single out the one class that was causing me problems either. I was then thinking of implementing my own Serializer to check for Bean and instanceof CharSequence.. but the fix I added was OK for what I needed. A fix or patch would be appreciated. |
Right, that does work due to how I agree that this needs to be addressed; above is just thinking out aloud about best ways to do it. |
CharSequence
subtypes as POJO instead of using ToStringSerializer
in Java 15
Duplicated issue: #3331 (closed) with similar example |
Quick note: working on this, but having big difficulties in getting Eclipse setup to work with specific JDK/JRE I need. |
CharSequence
subtypes as POJO instead of using ToStringSerializer
in Java 15CharSequence
subtypes as POJO instead of as String (JDK 15+)
Describe the bug
I have a class that implements CharSequence and in Java 14 and below the class was serialised correctly.
In Java 15 the JSON generated is
{"empty": false}
I believe the change was introduced in the CharSequence API by the introduction of the method isEmpty().
It appears the POJOPropertiesCollector._addGetterMethod collects the method isEmpty();
The class is then identified as a Bean type object, and uses a BeanSerializer to serialize the class. In Java 14 ToStringSerializer would be used to serialize the class.
Version information
Jackson 2.11.3
To Reproduce
See simple class to reproduce:
`
public class TestMapper
{
}
`
Expected behaviour
Expected "Hello World"
Actual
{"empty": false}
Running in Java 14 or below the expected result is returned
The text was updated successfully, but these errors were encountered: