eredo / dartson

Dartson is a Dart library that can be used to convert Dart objects into a JSON string.
MIT License
79 stars 29 forks source link

Dartson writes to private fields instead of using getter and setters #47

Closed AlexanderJohr closed 5 years ago

AlexanderJohr commented 6 years ago

I use a class with a private bool field and assign true to it. In the setter I make sure that the given value is not null (in case null is assigned in the deserialization process). The dart dev compiler always complains when there are bools with null values.

Dartson documentation points out, that it never serializes or deserializes private fields.

// private members are never serialized String _private = "name";

Yet it does for me and it also ignores my public getter and setters;

@Entity() class MyClass implements StaticEntity { bool _myPrivateBool = true;

bool get myBool => _myPrivateBool ;

void set myBool(bool value) { if (value != null) _myPrivateBool = value; }

void dartsonEntityDecode(Map obj, TypeTransformerProvider dson) { // ... this._myPrivateBool = obj["_myPrivateBool"]; // ... }

eredo commented 5 years ago

I'm closing this as the behaviour now has completely changed. However setter are still in progress in dartson 1.0.0-alpha.