Summary: I am required to submit a JSON request via C# where part of the payload changes based on certain business rules. I know all the possible structures, but have to use only the correct one in the request.
Example 1
{
"activity": {
"referenceId": "",
"data": {
"rents": 0.0,
"wages": 0.0
}
}
}
Example 2
{
"activity": {
"referenceId": "",
"data": {
"transport": 0.0,
"salaries": 0.0
}
}
}
Example 3
{
"activity": {
"referenceId": "",
"data": {
"water": 0.0,
"miscellaneous": 0.0
}
}
}
So, depending on some business rules, I have to change the parameters in "data". It's a bit more complex than just two property names, but I think the answer to this question as asked will be sufficient.
I have set up POCO's as per usual, but have no idea how to get them to work within this requirement.
I had the idea to create a "master" Data object and somehow only pass along the properties required, but I'm stumped at that point.
public class Rootobject
{
public Activity activity { get; set; }
}
public class Activity
{
public string referenceId { get; set; }
public Data data { get; set; }
}
public class Data //Inheriting from this master won't work.
{
public float water { get; set; }
public float miscellaneous { get; set; }
public float transport { get; set; }
public float salaries { get; set; }
public float rents { get; set; }
public float wages { get; set; }
}