I have set the following payload into Gson
's JsonObject
:
{
"backup": {
"addresses": [
"127.0.0.1"
],
"healthcheck_interval": "60",
"http": "https",
"port": "9001"
},
"cognito": {
"addresses": [
"127.0.0.1"
],
"http": "https",
"port": "9012"
},
"collector": {
"addresses": [
"127.0.0.1"
],
"healthcheck_interval": "60",
"http": "https",
"port": "9000"
},
"ds": {
"addresses": [
"127.0.0.1"
],
"http": "https",
"port": "9011"
},
"insight-analytics": {
"addresses": [
"127.0.0.1"
],
"http": "https",
"port": "9013"
},
"integrations": {
"addresses": [
"127.0.0.1"
],
"http": "https",
"port": "9014"
},
"server": {
"addresses": [
"127.0.0.1"
],
"healthcheck_interval": "60",
"http": "https",
"port": "9009"
},
"vigile": {
"addresses": [
"127.0.0.1"
],
"http": "https",
"port": "9443"
},
"walt": {
"addresses": [
"127.0.0.1"
],
"http": "https",
"port": "9010"
}
}
Test:
@Test(priority = 10)
public void parseServicesFileToGsonObject() {
JsonParser jsonParser = new JsonParser();
JsonElement rootNode = jsonParser.parse(response);
if (rootNode.isJsonObject()) {
JsonObject details = rootNode.getAsJsonObject();
}
}
I want to be able to store all the members of the JSON
into string array (backup
, cognito
, collector
, etc) in a manner that I can find the object using the string array to get further values (such as healthcheck_interval
, http
, port
, etc). I tried using streams for this cause with no success.
I wanna do this since it is quite possible that in the future names of the field could be changed (instead of backup
it could be changed to another name).