Khayam Gondal Khayam Gondal - 3 years ago 291
Java Question

Mapping JSON with Map and Normal Objects

I am getting following JSON

'external_gateway_info':{ },

Now routers is a simple object where I am mapping keys/values to my class but tenants are a HashMap.
I am unable to find a way where I can use a single mapper to map both routers and tenants to a single Object

My mapper

JSONObject jsonData = new JsonRepresentation(entity).getJsonObject();
RootModel rootModel = mapper.readValue(jsonData.toString(), RootModel.class);

Where snippet

public class RootModel {

private Router routers;
private Tenant tenants;

public RootModel(@JsonP

Answer Source

Apparently there is no cleaner way to use one Map for this kind of data. What I did, I used two different mappers to map routers and tenants.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download