My requirement is to parse through numerous backend responses, which can be either json or xml. Their response structure is not known to me now. So, i have to write a java tool in a such a way that, my tool should be able to parse through the response based on the configuration file, which will be configured by the services team before they run my tool as they will get to know the values, they will have to retrieve via my tool. For instance, if backend json or xml response looks like below and my configuration says Employee.details.referenced[0].type, the value retrieved via tool should be 'customer-support'. I will not be able to use pojo or something, which is coupled to the backend response as i will not know the backend response and my same tool should work for different backends, which output response in different structure:
Json:
{
"Employee": [
{
"id": "12345678",
"service": "ps",
"origin": {
"address": {
"addressLocality": "India"
}
},
"destination": {
"address": {
"addressLocality": "US"
}
},
"status": {
"timestamp": "2019-01-29T21:02:49Z",
"location": {
"address": {
"addressLocality": "Germany"
}
},
"Code": "xyz",
"description": "Services"
},
"details": {
"references": [
{
"number": "0003030891",
"type": "customer-support"
}
]
}
}
]
}
XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Employee>
<element>
<destination>
<address>
<addressLocality>US</addressLocality>
</address>
</destination>
<details>
<references>
<element>
<number>0003030891</number>
<type>customer-support</type>
</element>
</references>
</details>
<id>12345678</id>
<origin>
<address>
<addressLocality>India</addressLocality>
</address>
</origin>
<service>ps</service>
<status>
<Code>xyz</Code>
<description>Services</description>
<location>
<address>
<addressLocality>Germany</addressLocality>
</address>
</location>
<timestamp>2019-01-29T21:02:49Z</timestamp>
</status>
</element>
</Employee>
</root>
I tried to check on json parsers in java and xml saxparser. But, all seems to be bound to know the backend response in advance.