'Parsing line delimited JSON with Jackson generic types
Attempting to parse line delimited JSON with generic types, however JsonParser is unable to skip entire objects, only move the cursor to the next. I am trying to convert anything with a schema type to a POJO.
Example JSON: For convenience, I've formatted a single line of my line delimited JSON.
{
"schema": "person",
"name": "Bob",
"properties": {
"children": [
"Mary",
"Lucy"
],
"address": {
"schema": "address",
"street": "1000 Park Ave"
},
"vehicles": [
{
"schema": "vehicle",
"make": "BMW",
"year": "2021"
},
{
"schema": "vehicle",
"make": "Chevy",
"year": "2015"
}
]
}
}
Jackson code:
JsonFactory jfactory = new JsonFactory();
JsonParser jParser = jfactory.createParser(jsonFile);
while (jParser.nextToken() != JsonToken.END_OBJECT) {
System.out.println(jParser.getCurrentName() + " : " + jParser.getText());
jParser.nextToken();
}
The output is not comprehensible, so I will skip sharing it.
I do not think jParser is the correct tool, but how can I map the objects when they are generic in the JSON?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
