I am creating two different arrays from information in code. I need to concatenate(merge) those two into one and produce a json object to pass on to a different method. I would prefer to use gson because I am using those
I am using gson, and have tried so many different methods, I am completely lost. Any help?
NOTE: I've tried adding mList to asMap,
asMap.putAll(mList);
but get
putAll (java.util.Map<? extends java.lang.String,? extends java.lang.string>) in Map cannot be applied to (java.util.List <java.util.Map<java.lang.String,java.lang.String>>)
I have one array:
Map<String, String> asMap = new HashMap<>();
Which looks like:
{
"batchId":"25248e931e5948b990f528d26ee6a9f5",
"almServer":"server.com",
"almDomain":"EBUSINESS",
"almProject":"STERLING",
"testSetUrl":"http://test.com",
"testParameters":"{\"browser\":\"chrome\",\"browser-version\":\"56\",\"language\":\"english\",\"country\":\"USA\"}",
"startTime":"01/20/2018 06:37:05 PM",
"finishTime":"01/21/2018 05:30:25 AM",
"totalDuration":"10h 53m 19s 922ms",
"passed":159,
"testsExecuted":214,
"failed":52,
"notCompleted":3,
"testPassPercentage":"75.4"
}
A second:
List<Map<String, String>> mList = new ArrayList<Map<String, String>>();
Which looks like:
[
{
"runDuration":"9m 33s 642ms",
"testId":"12100",
"automatedTest":"CancelFullOrder",
"batchItemPosition":"1",
"runPosition":"1",
"executionDate":"01/21/2018",
"executionTime":"02:48:50 AM",
"runId":"69257",
"status":"PASSED"
},
{
"runDuration":"8m 56s 991ms",
"testId":"12101",
"automatedTest":"CancelOrderPartially",
"batchItemPosition":"2",
"runPosition":"1",
"executionDate":"01/21/2018",
"executionTime":"02:49:30 AM",
"runId":"69258",
"status":"PASSED"
}
]
I want to combine them into one jsonobject that would look like:
{
"batchId":"25248e931e5948b990f528d26ee6a9f5",
"almServer":"server.com",
"almDomain":"EBUSINESS",
"almProject":"STERLING",
"testSetUrl":"http://test.com",
"testParameters":"{\"browser\":\"chrome\",\"browser-version\":\"56\",\"language\":\"english\",\"country\":\"USA\"}",
"executedTests":[
{
"runDuration":"9m 33s 642ms",
"testId":"12100",
"automatedTest":"CancelFullOrder",
"batchItemPosition":"1",
"runPosition":"1",
"executionDate":"01/21/2018",
"executionTime":"02:48:50 AM",
"runId":"69257",
"status":"PASSED"
},
{
"runDuration":"8m 56s 991ms",
"testId":"12101",
"automatedTest":"CancelOrderPartially",
"batchItemPosition":"2",
"runPosition":"1",
"executionDate":"01/21/2018",
"executionTime":"02:49:30 AM",
"runId":"69258",
"status":"PASSED"
}
],
"startTime":"01/20/2018 06:37:05 PM",
"finishTime":"01/21/2018 05:30:25 AM",
"totalDuration":"10h 53m 19s 922ms",
"passed":159,
"testsExecuted":214,
"failed":52,
"notCompleted":3,
"testPassPercentage":"75.4"
}