0

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"
    }
}
Community
  • 1
  • 1
rmv
  • 3,195
  • 4
  • 26
  • 29
  • @JamesB I think OP referes to the fact that the keys, like 10869918, cannot be the name of any attribute in a bean. The only option here is a `Map>` – Pablo Lozano Jul 07 '14 at 14:17
  • What does the POJO look like that you are trying to map this json to? – Michael Wiles Jul 07 '14 at 14:47
  • I only have the JSON data and try to create suitable POJOs which match the data using Spring-Roo as rapid prototyping tool. The actual data set is more complex then the excerpt shown above. – rmv Jul 07 '14 at 15:05

1 Answers1

2

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.

Thomas
  • 87,414
  • 12
  • 119
  • 157
  • 1
    My idea exactly; don't map to an object, map to a collection instead. The data itself seems to represent a hashtable of sorts anyway, so it would be pretty strange to want to map that to a POJO. – Gimby Jul 07 '14 at 14:23