✅ How to parse this weird API ?
I have a very akward thing to do and I d'ont know if there is a clean way to do it.
In a REST API, there is two string fields
N.B: the "attribute" here have nothing to do with any .NET vocabulary, it's just a name, think of it like "foo" or "bar"
In my Domain I have a class with all possible properties
what I need to do is, depending on the AttributeName and AttributeValue given in the API, I want to create an instance of Product which has all everything equal to null except for the property for which we were given the name and value in AttributeName and AttributeValue. (there is always a single one)
For exemple
Another example,
In a REST API, there is two string fields
attributeName and attributeValue (for example { "attributeName" : "isAllowed" , " attributeValue" : "true"} and { "attributeName" : "productType" , " attributeValue" : "A50"} , in the API this is modelled by the following classN.B: the "attribute" here have nothing to do with any .NET vocabulary, it's just a name, think of it like "foo" or "bar"
In my Domain I have a class with all possible properties
what I need to do is, depending on the AttributeName and AttributeValue given in the API, I want to create an instance of Product which has all everything equal to null except for the property for which we were given the name and value in AttributeName and AttributeValue. (there is always a single one)
For exemple
{ "attributeName" : "isAllowed" , " attributeValue" : "true"} would result in a product Instance with product.IsAllowed = true and product.ProductType = null (and other fields will be null as well)Another example,
{ "attributeName" : "productType" , " attributeValue" : "A50"} would result in product Instance with product.IsAllowed = null and product.ProductType = A50 (and other fields will be null as well)