I have the following JSON:
{
"code":1000,
"message":"Success",
"data":{
"results":[
{
"lineId":"C4000LG2020253739",
"lineDiagnostics":{
"C4000LG2020253739":{
"ap":{
"broadbanddsthroughput":{
"broadbandDsThroughput":[
{
"average":104830,
"std":0,
"detection":0,
"numErrorFreeSamples":1,
"sampleMaxPercentile":107673,
"latestSampleTimestamp":1698160893000,
"sampleMax":107673,
"url":"http://blah-blah.com",
"videoQuality":7,
"serviceDetection":-1,
"percentile":[
104830
],
"latestSample":104830,
"primaryIp":"205.171.3.100",
"speedTestTrafficMB":56.9910995
}
]
},
"broadbandusthroughput":{
"broadbandUsThroughput":[
{
"average":37828,
"std":0,
"numErrorFreeSamples":1,
"sampleMaxPercentile":38393,
"latestSampleTimestamp":1698160893000,
"sampleMax":38393,
"url":"http://blah-blah.com",
"serviceDetection":-1,
"percentile":[
37828
],
"latestSample":37828,
"primaryIp":"205.171.3.100",
"speedTestTrafficMB":21.8231345
}
]
}
},
"interface":{
},
"station":{
},
"multiWan":{
}
}
},
"analysisDay":20231024
}
]
}
}
Under the lineDiagnostics, we have the "C4000LG2020253739": {...} and I need the contents from inside this object for my further calculations, could anyone please let me know how can this be achieved?
I am using Jackson to map the JSON values to a Java class.
Note: This particular string value "C4000LG2020253739":{...} will change with every microservice call(and not the contents inside this{...}), so I am facing problem with creating a general purpose Java class for this JSON structure.
I am using Jackson to map the JSON values to a Java class:
public class Class1{
//historical speed response structure : map from json response
String code;
String message;
@JsonProperty("data")
DataSpeeds dataSpeeds;
...}
public class DataSpeeds {
@JsonProperty("results")
List<Results> results;
@JsonProperty("lineId")
String lineId;
...}
public class Results {
String lineId;
@JsonProperty("lineDiagnostics")
LineDiagnostics lineDiagnostics;
...}
public class LineDiagnostics {
@JsonProperty("ap")
Ap ap;
...}
Inside the LineDiagnostics object, I need to map the "C4000LG2020253739":{...} from JSON, how can this be done? any pointers?
LineDiagnosticsobject to aHashMap.Resultclass, change the type of the fieldlineDiagnosticstoMap<String, LineDiagnostics>from plainLineDiagnostics. Jackson will then populate the keys of this map withC4000LG2020253739, etc. and the values as the corresponding unmarshalledLineDiagnosticsinstances.