Replies: 4 comments 7 replies
-
Beta Was this translation helpful? Give feedback.
-
The provided link suggest to add the known type as an attributes to the base class which is not possible in my case, and this way kill the polymorphism with oop and the ability to expose extensibility point and work with unknown type which make this serializer unusable in this case, is there another way than the one mentioned in the link? |
Beta Was this translation helpful? Give feedback.
-
Yes i did something like that which i will need to register the known type at startup but it will add more headache for mapping, not always you need to know what class is implementing your interface specially if you developing a library for use outside your project and here is the issue |
Beta Was this translation helpful? Give feedback.
-
Why [JsonDerivedType(typeof(WeatherForecastBase), typeDiscriminator: "base")]
[JsonDerivedType(typeof(WeatherForecastWithCity), typeDiscriminator: "withCity")]
public class WeatherForecastBase
{
public DateTimeOffset Date { get; set; }
public int TemperatureCelsius { get; set; }
public string? Summary { get; set; }
}
public class WeatherForecastWithCity : WeatherForecastBase
{
public string? City { get; set; }
} I want to set on derived class [TypeDiscriminator("base")]
public class WeatherForecastBase
{
public DateTimeOffset Date { get; set; }
public int TemperatureCelsius { get; set; }
public string? Summary { get; set; }
}
[JsonDerivedType("withCity")]
public class WeatherForecastWithCity : WeatherForecastBase
{
public string? City { get; set; }
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm developing a library that will generate api at the end and this api will need to deserialize an interface as a result, so the types is not known yet and i don't want to add a headache for mapping types in startups, this library is very disappointing and unusable as it add a lot of dependency and logic to and from the serializer to the code, i think it still need a lot of work and the problem is its used by default and forced by microsoft in my places.
Is there a way to do this?
Beta Was this translation helpful? Give feedback.
All reactions