-
-
Notifications
You must be signed in to change notification settings - Fork 444
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
Use toString for enum serialization #2220
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2220 +/- ##
============================================
+ Coverage 80.61% 80.64% +0.02%
- Complexity 3355 3357 +2
============================================
Files 240 240
Lines 12327 12331 +4
Branches 1634 1636 +2
============================================
+ Hits 9938 9944 +6
+ Misses 1782 1781 -1
+ Partials 607 606 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Hey @adinauer, really thanks for the quick response. But I am thinking if this solution wouldn't be better in the |
As an optimmization it could be added to both. But it should be in |
@@ -46,6 +46,8 @@ public void serialize( | |||
serializeCollection(writer, logger, Arrays.asList((Object[]) object)); | |||
} else if (object instanceof Map) { | |||
serializeMap(writer, logger, (Map<?, ?>) object); | |||
} else if (object.getClass().isEnum()) { | |||
writer.value(object.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WHat's about object..name()
? Does it return the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd have to use reflection to invoke .name()
. By default .toString()
should be the same as .name()
. It also allows overriding the value that is serialized.
📜 Description
Use
toString()
for enum entries being serialized.💡 Motivation and Context
JsonReflectionObjectSerializer
would consume lots of memory when serializing an enum entry where the enum has more than just a few entries.Fixes #2219
💚 How did you test it?
Unit Test
📝 Checklist
🔮 Next steps