I have this use case where in I would need to dynamically create java objects out of json input and insert the data into sql tables.

I tried using gson APIs but unfortunately we need to specify strucuture of that class (Car.class). Is it possible to dynamically achieve the above use without having to specify the structure of the class(Car.class)

Gson gson = new Gson();

Car car = gson.fromJson(json, Car.class);

Thanks in advance

Hi,

I highly doubt it's possible. If we don't know the class structure than we can't use it after parsing.

I have seen (in Groovy) examples where the JSON object is converted into a map and you can, after that, get all keys and values easily.

I have found some examples with Jackson here.

Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.