Replies: 1 comment 1 reply
-
What do you expect/want to happen here? Given the following: class Zoo // Added `class` here
{
public List<Animal> Animals { get; set; } // I added a name here
}
abstract class Animal
{
public string Name { get; set; }
}
class Cat : Animal
{
public int PurrDecibel { get; set; }
}
class Dog : Animal
{
public bool BarksAtMailman { get; set; }
} var zoo = new Zoo
{
Animals = new()
{
new Cat()
{
Name = "My Cat",
PurrDecibel = 80,
},
new Dog()
{
Name = "My Dog",
BarksAtMailman = true,
},
},
};
JsonConverter.Serialize(zoo); What is expected here? This? {
"animals": [
{
"name": "My Cat"
},
{
"name": "My Dog",
}
]
} or this? {
"animals": [
{
"name": "My Cat",
"purrDecibel": 80
},
{
"name": "My Dog",
"barksAtMailman": true
}
]
} or even this? {
"animals": [
{
"name": "My Cat",
"purrDecibel": 80,
"barksAtMailman": false // The default value for a bool
},
{
"name": "My Dog",
"purrDecibel": 0, // The default value for an int
"barksAtMailman": true
}
]
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Like serializarion/deserialization
Zoo
?If so, how?
Thanks :)
Beta Was this translation helpful? Give feedback.
All reactions