Skip to content

Allow accepting a JSON substring using a string instead of throwing an exception #5233

@kfyty

Description

@kfyty

Is your feature request related to a problem? Please describe.

no, this is my own need and idea.

Describe the solution you'd like

such as json:

{
	"name": "root",
	"child": {
		"name": "child"
	}
}

and i want to deserialize it into the following Java object:

public class TestPojo {
    private String name;
    private String child;
	
	// getter setter
}

I hope the deserialization can be successful, and the result of deserialization is:
name=root
child={"name":"child"}

Usage example

@Test
public void acceptSubJsonTest() throws Exception {
	String json = "{\"name\":\"root\"," +
			"\"child\":{\"name\":\"child\"}," +
			"\"children\":[{\"name\":\"children\"}]," +
			"\"childrenList\":[{\"name\":\"childrenList\"}]}";
	ObjectMapper mapper = new ObjectMapper();
	TestPojo testPojo = mapper.readValue(json, TestPojo.class);
	Assertions.assertEquals(testPojo.getChild(), "{\"name\":\"child\"}");
	Assertions.assertEquals(testPojo.getChildren(), "[{\"name\":\"children\"}]");
	Assertions.assertEquals(testPojo.getChildrenList().get(0), "{\"name\":\"childrenList\"}");
}

Additional context

I have submitted a PR to support this issue, please click here to view.

Metadata

Metadata

Assignees

No one assigned

    Labels

    to-evaluateIssue that has been received but not yet evaluated

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions