Parsing an object with several dynamic properties

Hi all,

Look at this object:

  orderId: '50314b8e9bcf000000000000',
  products: [
      id: '507f1f77bcf86cd799439011',
      sku: '45790-32',
      name: 'Monopoly: 3rd Edition',
      price: 19,
      quantity: 1,
      category: 'Games'
      id: '505bd76785ebb509fc183733',
      sku: '46493-32',
      name: 'Uno Card Game',
      price: 3,
      quantity: 2,
      category: 'Games'

and imagine that some properties within products are dynamic. For example imagine that quantity and category are dynamic. if this is coming through as a request, how can we get ServiceStack to parse this into an object for further consumption?

Whist we don’t recommend dynamic parsing you can have a look at different dynamic parsing examples.

Thanks mythz. What do you recommend for this scenario where custom attributes / properties need to be sent to the backend and stored appropriately? This is a high transaction service btw in case performance is massively affected.

Can you just save the raw JSON?

I dislike dynamic schemas for similar reasons as dynamic vs static typing, but if this schema wasn’t fixed I’d still be deserializing into a Type which allows for unstructured data like a Dictionary<string,string>, e.g:

class Order
  public string OrderId { get; set; }
  public List<Dictionary<string,string>> Products { get; set; }

Can I do that? Deserialize it into a dictionary if I only care about one level in the hierarchy?

Sure, just try it out. is great for explanatory coding.