// gettors, settors for vendor if you need them
List<VendorWrapper> vendors = new ArrayList<VendorWrapper>();
// gettors, settors for vendors if you need them
// in your deserialization code:
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readValue(jsonInput, VendorsWrapper.class);
Finally, you might use the Jackson Tree Model to parse this into JsonNodes, discarding the outer node, and for each JsonNode in the ArrayNode, calling:
I'd also like to see a solution using something like UNWRAP_ROOT_VALUES, only 1 level deeper, but I don't think it's possible. Another option of course is to use a custom deserializer, and just add hooks to look for the actual objects you're interested in and discard everything else, or to use the Jackson Tree Model approach, throw away the top-level JsonNode, and take the JsonNodes that wrap your Vendors, call getTextValue, and pass that to mapper.readValue. Jackson really gives you a surfeit of options.
I'm assuming that you're using the Jackson Data Binding model.
Similarly, instead of using UNWRAP_ROOT_VALUES, you could also define a wrapper class to handle the outer object. Assuming that you have correct Vendor, VendorWrapper object, you can define:
Thank you, this is how I was doing it I just hoped there was a better way. I'll mark it as correct.
That might result in less code, but it seems no less clumsy than using two wrappers.
The first is using a special Jackson config property. Jackson - since 1.9 I believe, this may not be available if you're using an old version of Jackson - provides UNWRAP_ROOT_VALUE. It's designed for cases where your results are wrapped in a top-level single-property object that you want to discard.
The second is using wrapper objects. Even after discarding the outer wrapper object you still have the problem of your Vendor objects being wrapped in a single-property object. Use a wrapper to get around this:
Your data is problematic in that you have inner wrapper objects in your array. Presumably your Vendor object is designed to handle id, name, company_id, but each of those multiple objects are also wrapped in an object with a single property vendor.