I'm trying to figure out how to better understand serialization / deserialization of JSon nested Java objects in Spring MVC.
My domain model is as follows:
public class Cart { private String id; private Customer customerID; private Checkout checkoutID; private List<CartProduct> itemCatalogList; *** ... getters & setters ... *** } public class ProductCart { private String sku; private String color; private String sizeBase private int qty; *** ... getters & setters ... *** } public class Checkout { private String id; private String billingAddress; private String shippingAddress; private Cart cartID; *** ... getters & setters ... *** }
The JSon I was thinking about looks something like this:
Photo:
{ "cart": { "$oid": "51f631cb84812abb04000006" }, "shippingAddress" : "5h avenue - new york", "billingAddress" : "5h avenue - new york" }
basket
{ "customer": { "$oid": "5174da574940368a9126e8dc" }, "items_catalog": [ { "sku": "00075161", "color": "ff99cc", "size_base": "IT_25", "qty": 3, }, { "sku": "00075161", "color": "ff99cc", "size_base": "IT_27", "qty": 2, }, { "sku": "00075161", "color": "ff99cc", "size_base": "IT_29", "qty": 1, } }
Assuming this is a viable domain model and a json document, how in Spring could I create validation starting with JSon?
My problem is that I donβt know how to "explode" $ oid in the json checkout and basket to create a Java Beans check and basket:
Is there a way to do this automatically with Jackson?
or do I need to create some kind of interceptor for processing, for example, checkout json, in order to get the basket, and then perform a mapping to POJO?
(- or is there a third way?)
Thanks so much for any advice.