C
C#9mo ago
Videoscope

Issue with deserializing Enums in saved JSON

Hey, I've been trying to deserialize a list of cards I serialized in C#, the issue I'm having is it converts all the enums perfectly except for the cardResource enum, after researching I learned you could use the stringConverter and it might help, and it did work in converting the enums into strings instead of ints and made the JSON more readable, but still for the cardResource I am always getting the value of 0 or Move
No description
7 Replies
Videoscope
VideoscopeOP9mo ago
example JSON for card:
{
"name": "Rage",
"color": "Red",
"cardType": "Basic",
"basicAction": {
"actionType": "Basic",
"choices": [
{
"resources": [
{
"resource": {
"resource": "Attack",
"attackBlockAspect": null
},
"amount": 2
}
],
"negatives": null
},
{
"resources": [
{
"resource": {
"resource": "Block",
"attackBlockAspect": null
},
"amount": 2
}
],
"negatives": null
}
]
},
"empoweredAction": {
"actionType": "Empowered",
"choices": [
{
"resources": [
{
"resource": {
"resource": "Attack",
"attackBlockAspect": null
},
"amount": 5
}
],
"negatives": null
}
]
}
}
{
"name": "Rage",
"color": "Red",
"cardType": "Basic",
"basicAction": {
"actionType": "Basic",
"choices": [
{
"resources": [
{
"resource": {
"resource": "Attack",
"attackBlockAspect": null
},
"amount": 2
}
],
"negatives": null
},
{
"resources": [
{
"resource": {
"resource": "Block",
"attackBlockAspect": null
},
"amount": 2
}
],
"negatives": null
}
]
},
"empoweredAction": {
"actionType": "Empowered",
"choices": [
{
"resources": [
{
"resource": {
"resource": "Attack",
"attackBlockAspect": null
},
"amount": 5
}
],
"negatives": null
}
]
}
}
Videoscope
VideoscopeOP9mo ago
No description
Videoscope
VideoscopeOP9mo ago
as you can see just loading this json, it doesnt convert the enum properly
Videoscope
VideoscopeOP9mo ago
\
No description
Videoscope
VideoscopeOP9mo ago
while it converts all the other ones fine the warning highlighting is also just that it could be null and I am casting it to a nonnullable so that shouldnt really be an issue or is it better to just use xml?
Pobiega
Pobiega9mo ago
Can you post your model too?
Videoscope
VideoscopeOP9mo ago
It’s just a normal class, should I make a copy that’s just a model, and serialize that then? I’m not on my pc right now*
Want results from more Discord servers?
Add your server