I have following DTO
public class Foo
{
public ServiceStack.Text.JsonObject Bar { get; set; }
}
Foo.Bar can be one out of 3 other DTOs
Somewhere in my code I would like to map/convert/deserialize Foo.Bar to the concrete DTO (I know that ServiceStack.Text.JsonObject implements System.Collection.Generic.Dictionary<string, string> – interestingly values, which were transmitted as non-string, get into my ServiceStack.Text.JsonObject-instance as strings).
So I have tried
ServiceStack.Text.JsonExtensions.JsonTo<ConcreteDTO>(foo.Bar, ???)
but it takes a key-selector as the 2nd parameter – but I do not want to convert a single value, rather I would go for the whole instance.
I also know that there is ServiceStack.Text.JsonExtensions.ConvertTo<T>(JsonObject jsonObject, Func<JsonObject, T> convertFn), but I do not want to convert the jsonObject handcoded.
So, how can I solve this?
EDIT:
Just to be clear – I do not want to go the detour and serialize the JsonObject-instance to a json-string just to deserialize it … Is there any direct deserialization option from JsonObject?
So … what I ended up with: