Skip to content

feat: Allow accepting a JSON substring using a string instead of throwing an exception. #5232

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

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from

Conversation

kfyty
Copy link

@kfyty kfyty commented Jul 23, 2025

(for #5233)

This PR implementation allows the use of a string to accept a JSON substring during deserialization.
And provided unit testing for verification, as well as backward compatibility.

@JooHyukKim
Copy link
Member

Can you add related github issue?

@kfyty
Copy link
Author

kfyty commented Jul 23, 2025

Can you add related github issue?
Hello, there is no related issue, it was discovered during my own use.
Do I need to create a new issue and then relate it?


@Test
public void acceptSubJsonTest() throws Exception {
String json = "{\"name\":\"root\"," +
Copy link
Member

Choose a reason for hiding this comment

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

* Feature that allow accepting a JSON substring using a string
* instead of throwing an exception.
*<p>
* Feature is enabled by default.
Copy link
Member

Choose a reason for hiding this comment

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

this is disabled by default - so the comment is wrong

Copy link
Author

Choose a reason for hiding this comment

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

thanks, I will fix it.

@pjfanning
Copy link
Member

Can you add related github issue?
Hello, there is no related issue, it was discovered during my own use.
Do I need to create a new issue and then relate it?

Create a new issue for discussion. I would suggest not spending more time on the implementation until there is agreement that we want to add a feature like this.

@kfyty
Copy link
Author

kfyty commented Jul 23, 2025

#5233

@kfyty
Copy link
Author

kfyty commented Jul 23, 2025

#5233

@pjfanning I have created a new issue to discuss this feature.

@@ -19,6 +19,12 @@
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.type.LogicalType;

import java.io.IOException;
Copy link
Member

Choose a reason for hiding this comment

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

Please do not re-order or expand import statements. Lots of noise & something we'll revert over time anyway.

@cowtowncoder
Copy link
Member

As things are this would not be accepted: it's a very specialized case that does not fit well with Jackson modeling.

For your use case I would write a custom String deserializer, use that.

return defaultDeserialize(p, ctxt);
}

StringBuilder builder = new StringBuilder();
Copy link
Member

@cowtowncoder cowtowncoder Jul 24, 2025

Choose a reason for hiding this comment

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

Ugh. This is madness... are we trying to re-construct JSON BACK from decoded JSON?

No, I don't think this is something to add.

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.

4 participants