-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: 2.x
Are you sure you want to change the base?
Conversation
Can you add related github issue? |
|
|
||
@Test | ||
public void acceptSubJsonTest() throws Exception { | ||
String json = "{\"name\":\"root\"," + |
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.
- use the method a2q which converts apostrophes to double quotes
- the text then should use apostrophes instead of quotes - the advantage is that you don't need to escape apostrophes making the text easier to read
- example -
mapper.readValue(a2q("{'notRudy':{'a':3}}"), Bean.class);
* Feature that allow accepting a JSON substring using a string | ||
* instead of throwing an exception. | ||
*<p> | ||
* Feature is enabled by default. |
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.
this is disabled by default - so the comment is wrong
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.
thanks, I will fix 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. |
@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; |
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.
Please do not re-order or expand import statements. Lots of noise & something we'll revert over time anyway.
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 |
return defaultDeserialize(p, ctxt); | ||
} | ||
|
||
StringBuilder builder = new StringBuilder(); |
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.
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.
(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.