Basically, the design of the JSON and the design of the domain don't match up. So you can either alter the JSON, or you can alter the domain objects.
Altering the JSON to fit the domain
- You'll need to either remove the "-" from theThe property names, or that have qualifiers for the properties"-" in your objectsthem wont parse nicely in jackson, so they will need to be removed.
- There's no need to haveHaving the class names in front of each object definition withinname before eachof the JSONobjects isn't going to help. Jackson will trip up onexpect these to be properties, so the Class names will need removing or replacing with property names.
- You should be using propertyProperty names within the JSON instead ofmust be provided as they are in the class namesdomain objects in order for jackson to parse them. You can't just say here's an object and then start a list, the list must have a property name/
After I'd adjusted a fewthese things in the JSON, I got it to parse with the provided domain objects. The JSON I ended up with looked like this:
Obviously, this is only going to work if you're able to modify the JSON, either at source or in some preprocessing, so I'm going to have a poke around and see if I can make it parse without editing the JSON and just do some clever things with the domain object your provided.
EDIT: Found a way to work with JSON and changeAltering the domain to fit the JSON
Firstly, the main issues is having the Class names as the property identifiers. That makes it quite difficult to work with this JSON in the usual manner. I've added an OverallWrapper class that has a TestSuite propertyhad to cater for the TestSuite class name in the JSON. I've then also addedadd a TestCaseDataWrapper classcouple of wrapper classes to cater forget around the TestCaseData class names in the listbeing in the JSON. I also removed the TestCase class al together. All of the rest of the properties can be handled with the @JsonProperty annotation.
Basically, the domain provided didn't match the design of the JSON, so I've made modifications for it to work.
I've added an
OverallWrapperclass that has aTestSuiteproperty to cater for the TestSuite class name in the JSON.I've also added a
TestCaseDataWrapperclass to cater for the TestCaseData class names in the list in the JSON.I removed the TestCase class all together as that just became a property on one of the other classes.
Then to make the property names match up with the objects, I've used the
@JsonPropertyannotation.
Here are the classes after the modifications, and the ultimate parser test method that works and parses the JSON. (again, excuse all the escape characters in the JSON string)
Summing up
The ultimate issue is that the domain doesn't marry up with the JSON.
Personally I prefer to change the JSON to marry up to the domain, as the domain seems to make sense in it's design and requires less customization and forcing.
However, I do accept that you may not have that choice, hence the redesign of the domain.