-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compare with JsonSubTypes package. #35
Comments
hey, yep, so actually some time ago i needed an ability to ser/deser polymorphic types and 1st solution i found https://github.com/manuc66/JsonSubTypes , but there is a critical nuance for me. Example from JsonSubTypes doc: [JsonConverter(typeof(JsonSubtypes), "Kind")]
public interface IAnimal
{
string Kind { get; }
}
public class Dog : IAnimal
{
public string Kind { get; } = "Dog";
public string Breed { get; set; }
}
public class Cat : IAnimal {
public string Kind { get; } = "Cat";
public bool Declawed { get; set;}
}
This is actualy why i desided to create my own solution. So as you can see on 2 block (from my lib doc), it doesn't change the class structure in any way, it works from "outside". Im working a lot with Mongo, so you can find in mongo driver [JsonConverter(typeof(JsonKnownTypesConverter<BaseClass>))]
[JsonDiscriminator(Name = "myType")] //add custom discriminator name
[JsonKnownType(typeof(BaseClass1Heir))] //could be deleted if you didn't turn off UseClassNameAsDiscriminator
[JsonKnownType(typeof(BaseClass2Heir), "myDiscriminator")]
public class BaseClass { ... }
public class BaseClass1Heir : BaseClass { ... }
public class BaseClass2Heir : BaseClass { ... } So why to use mine or their, so ask yourself:
|
I leave it here, maybe add to readme some day, just to lazy to do that xD |
Дмитрий, спасибо |
There is a similar package https://github.com/manuc66/JsonSubTypes
Can you explain in Readme, what are pro and cons of your package , why someone should use your or their library?
The text was updated successfully, but these errors were encountered: