I am using a Mongo database and the backend with Java Spring. Originally it had this structure:
"defaultActivation":{
"accounts": ["500026", "500027"]
}
And I mapped it with the following structure in Java:
private Map<String, Set<String>> defaultActivation;
But now the structure is a bit more complex:
"defaultActivation":{
"accounts": ["500026", "500027"],
"paymentsModel": {
"TSP": ["CO", "AR"],
"PSP": ["CO"]
}
}"
How can I map this new structure, should I create another model in Java?
You can use Gson for this kind of thing, specifically your problem can be stated as follows:
you have this json
You should create an object (class)
PaymentModel
with the attributesTSP
andPSP
which are of type array. For the parent object you should create a classDefaultActivation
with the attributesaccount
of type array and the other attribute would be of typePaymentModel
With a Gson instance you only need to make a call to