dson
dson copied to clipboard
class with getter field throws FieldNotFoundException when using fromMap/fromJson
I read the generated code, and the SerializableMap's code please allow me using the easiest way
- fromMap method will try to assign getter with value, because it uses class mirror fields as the list, and class mirror fields contains getter field.
- []= method will throw FieldNotFoundException when unsupported key is given
- So, fromMap will throw FieldNotFoundException, when getter field exists.
Could you show me your code?
Sorry, now I understand the error. By the moment you only have three options:
- You can add a setter so
dson
always find it - You add
@ignore
annotation to the getter and it should be ignored bydson
. - You could override the
addAll
method so it looks something like next:
@serializable
class Person extends _$PersonSerializable {
int _id;
int get id => _id;
@override
addAll(Map map) => PersonClassMirror.setters.forEach((setter) => this[setter] = map[setter]);
}
I'm going to fix this in future versions.
I think that the problem still persists. And using @ignore
did not work for me. Getters like the following will still get serialized but it fails once object is being reconstructed.
@ignore
bool get isRunning => status == Task.RUNNING;
@ignore
bool get isPaused => status == Task.PAUSED;
@luisvt Can the throwfieldnotfoundexception be removed?
What do you mean?