Skip to content

Added unit test for Issue-4214 #4215

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

Merged
merged 1 commit into from
Nov 27, 2023
Merged

Conversation

dvhvsekhar
Copy link
Contributor

See #4214 for more details.

Comment on lines 707 to 710
if (ser == null || (value instanceof EnumSet && ser.getClass() != EnumSetSerializer.class)) {
// if value instance of EnumSet, use EnumSetSerializer for EnumSet instead of
// generic CollectionSerializer, since de-serialization uses EnumSetDeserializer,
// if property value is of type EnumSet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, but this is not a valid solution. The solution does not seem to fit overall and class design in any way. Is there simliar implementation in BeanPropertyWriter? Or any other pattern that you refered to?

Copy link
Contributor Author

@dvhvsekhar dvhvsekhar Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree that the fix is not fitting in overall design of this class, just added this workaround here to explain the problem better. I tried to set the serializer while initializing the instance of this class, but the runtime type information of the property value is not available at the time of initializing of this class's object.


public void testSerialization() throws Exception {
ObjectMapper mapper = jsonMapperBuilder().build()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never disable this for unit tests (except when testing feature itself) -- it has a nasty habit of hiding real problems, and developers wrongly enable it out of habit (there are good reasons to enable it too, just not always).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will remove this configuration.

.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
// this type information is needed in json string, for this test
.activateDefaultTyping(BasicPolymorphicTypeValidator.builder().allowIfBaseType(Object.class).build(),
DefaultTyping.EVERYTHING);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. And of course it's EVERYTHING that causes problems. :)

@cowtowncoder
Copy link
Member

@dvhvsekhar Would it be possible to change the PR to just have failing test? It should be moved under src/test/java/.../failing so as not to block CI; and name should contain id 4214 to indicate issue it is related with.
With failing test it would be easier for anyone to try a fix. Fix proposed here is unfortunately not acceptable, but test seems valid.

@dvhvsekhar
Copy link
Contributor Author

dvhvsekhar commented Nov 24, 2023

should be moved under

@cowtowncoder , can you please check now? I incorporated all suggestions.

@dvhvsekhar dvhvsekhar changed the title Issue-4214: Use EnumSetSerializer, if property is referring EnumSet at runtime Added unit test for Issue-4214 Nov 24, 2023
@cowtowncoder cowtowncoder merged commit 3aa59b9 into FasterXML:2.17 Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants