I'm receiving some oddly formatted JSON that I want to store in a single object. It looks something like this:
{
"parentObject":
{
"id": 123456,
"pointlessChildObject":
{
"stringThatCouldBeStoredInParent": "test",
"epochTimeThatCouldBeStoredInParent": "1520452800"
}
}
}
At first, I thought this would be simple thanks to a solution by Brian Rogers that I found: Can I specify a path in an attribute to map a property in my class to a child property in my JSON?
However, if you implement this solution, you can't use another converter for converting those values into something else at the same time (A nested [JsonConverter(typeof(SecondsEpochConverter))]
for the epoch time for example). And of course, because this is C#, you can't have a set that's different than your type (convert int
to DateTime
in set). I'm trying to add code to Brian's solution such that it calls the nested converter, but now we're getting into ridiculous territory; I'm creating a single use JSONTextReader
just to have the value passed to the nested converters, and I'm pretty sure I'm overthinking this.
Does anyone know of a better solution?