Expected Behavior
The JSON data should be correctly read and parsed regardless of whether it is an array or an object. The implementation should check the type of the root node and handle it accordingly. For instance, if the JSON data is an array, it should be read into a List
// Todo 1. ~~Modifying Json objects The objects you've added are all objects with a depth of 1. I will modify the Json objects a bit more, so that the test case works with different types of objects.~~ Done
- Look at how other open source Json readers are using it(ex springboot JsonReader), and reference on this.
Current Behavior
Currently, the code assumes that the JSON data is always in array format and tries to read it into a List
Context
- JSON Type Check: The current implementation does not check whether the JSON data is an array or an object, leading to potential failures. The modified code uses JsonNode to inspect the type of the root node.
- ObjectMapper Reuse: The code reuses the ObjectMapper instance for reading and converting JSON data.
- Stream API: When the JSON data is an array, the modified code uses the Stream API to traverse the JsonNode, parse each node, convert it to a Document object, and collect these objects into a list.
- Type Conversion: The modified code uses the ObjectMapper's convertValue method to convert JsonNode to Map
.
Please see as below * #750
Comment From: markpollack
Thanks for the PR. Will get it into M2
Comment From: csterwa
Closed as merged