Closed Lars-Sommer closed 1 year ago
well, that should be the easy one, it's not obvious that constructor parameter actionType
needs to be mapped to json field type
, so you should tell it explicitly how to operate:
@JsonSerializable()
class TestModel {
EActionType type = EActionType.None;
TestModel(@JsonProperty(name: 'type') EActionType actionType) {
type = actionType;
}
}
This should do the trick, if not let me know.
In your case you have different field names, but there are more cases around that, like:
type
and you can set it via constructor only, but you are giving constructor parameter same name type
that case is not resolved automagically yet 😄 @jsonSerializable
class Model {
EActionType _type = EActionType.None;
EActionType get type {
return _type;
}
Model(EActionType type) {
_type = type;
}
}
Makes great sense, and it works ofc :) Thanks alot! 🍺
Wow, so generous, thank you so much appreciate that. All I can do for you is my pleasure, challenge me whenever you like
This library is priceless, and your ability to help and sort out issues so fast is incredible!
I have this enum:
I Have this class:
I have this json:
Deserializing this works just fine 👌
But I need a constructor in my class to instantiate the model in my code logic:
Now the deserializing fails with:
TypeError (type 'Null' is not a subtype of type 'EActionType')
If I remove the actionType, so the constructor is empty, the deserialization works fine.
Any clues? 🤔