M
M
Maxim2013-07-10 20:49:47
Java
Maxim, 2013-07-10 20:49:47

json -> java mapping?

Is there any way to easily and naturally map a json document like this:

{
    "columns" : [ "name", "description", "id" ],
    "data" : [ [ "Train", "Поезда", 36 ], [ "Ship", "Корабли", 35 ], [ "Plane", "Самолеты", 34 ] ]
}

For a list of objects of this class:
class Transport {
    String id;
    String name;
    String description;
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
gvsmirnov, 2013-07-10
@gvsmirnov

There are many great frameworks that allow you to serialize/deserialize JSON into java objects.
For example code.google.com/p/google-gson/

D
Dinapoli, 2013-07-10
@Dinapoli

Try this tool - code.google.com/p/json-simple/
Works without problems and is quite convenient. In addition, some semblance of it is used in EE 7, where JSON support was added out of the box.

M
mrstrictly, 2013-07-12
@mrstrictly

Wonderful tool - Jackson: wiki.fasterxml.com/JacksonHome
Specifically for your example, a powerful feature is that Jackson supports deserialization into polymorphic types. This is written here: github.com/FasterXML/jackson-annotations#handling-polymorphic-types

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question