Search code examples
javajsonjacksonanonymous-typesclass-structure

How to parse JSON data without key names into a Java class structure?


I successfully followed the example Simple Spring code to parse JSON into a Java class structure using Jackson.

Now i am looking for a hint how to do the same for JSON data without key names, e.g.

{
    "10869918": {
        "BRANCH": "Dienstleistungen", 
        "SECTOR": "Diverse"
    }, 
    "12254991": {
        "BRANCH": "Luft- und Raumfahrtindustrie", 
        "SECTOR": "Logistik"
    }, 
    "12302743": {
        "BRANCH": "Touristik und Freizeit", 
        "SECTOR": "Medien/Freizeit"
    }
}

Solution

  • I doubt this is possible with a POJO-JSON mapper. You could use libraries like json-simple to parse the JSON string into Java objects (which basically are maps and lists) and access values like "10869918" by reading the keys of those maps.