Skip to content
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

Adding Duplicate key check in JacksonJrsTreeCodec #127

Merged
merged 14 commits into from
Mar 11, 2024

Conversation

Shounaks
Copy link
Contributor

Issue #51 : A check was missing for duplicate keys.

@Shounaks Shounaks marked this pull request as ready for review February 28, 2024 17:28
@@ -60,6 +62,9 @@ private JrsValue nodeFrom(JsonParser p) throws IOException
Map<String, JrsValue> values = _map();
while (p.nextToken() != JsonToken.END_OBJECT) {
final String currentName = p.currentName();
if(JSON.Feature.FAIL_ON_DUPLICATE_MAP_KEYS.enabledByDefault() && values.containsKey(currentName)){
Copy link
Member

Choose a reason for hiding this comment

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

Did you read my notes on #51? This does not work, it only considers default setting for feature but not its actual current state.

So without solving that problem this issue cannot really be solved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for pointing that out. As you said, TreeCodec doesn't have JSON as a parameter, so we cannot bring the JSON value of the current state up to this point. and its not a part of this library. (and also it doesn't make sense to change a library API just for a single line of code in another API. How should we tackle this problem... ☹️

Copy link
Member

Choose a reason for hiding this comment

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

Ideally configuration would be passed -- maybe there is something I overlooked earlier, as I did not spend tons of time on it? I am open to suggestions, as always.

@Shounaks
Copy link
Contributor Author

Shounaks commented Mar 5, 2024

@cowtowncoder , how about the extension storing the config information? That makes sense, that when we register the extension, we should have the configuration stored as well 🙌

return JSON.builder()
// 13-Feb-2020, tatu: There are 2 different ways actually..
// .treeCodec(new JacksonJrsTreeCodec())
.register(new JrSimpleTreeExtension(config))
Copy link
Member

@cowtowncoder cowtowncoder Mar 5, 2024

Choose a reason for hiding this comment

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

This is backwards incompatible change, breaking all existing users. I don't think that is
doable.

But there are other ways to achieve this, suggested below.

@cowtowncoder
Copy link
Member

Ok, no, let's not force passing of JSON on constructor of codec.

Instead, we should probably add a callback in codec that JSON can call to pass configuration, called when codec is being registered.
That callback could pass JSON, or -- if there's a clean way -- pass just feature flags?

@cowtowncoder
Copy link
Member

@Shounaks I went ahead and added #131 so extensions now have a way of figuring out configuration. I also updated this PR to use the setting.

@Shounaks
Copy link
Contributor Author

Shounaks commented Mar 8, 2024

Oh awesome! this is nice way to handle the state. I didn't know there was an Extension context!! that makes much more sense.

Thanks for help 😃 @cowtowncoder

@cowtowncoder cowtowncoder merged commit cec7bac into FasterXML:2.17 Mar 11, 2024
4 checks passed
@cowtowncoder
Copy link
Member

Thank you @Shounaks -- made minor tweaks, merged in for 2.17.0

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.

2 participants