Skip to content

Don't serialize/deserialize private fields especially when they are encapsulated #75

Closed
@AlexanderJohr

Description

@AlexanderJohr

As descriped in #74 I can't change the fact that my bool are overwritten by null, because the field isn't in the json. My thought was, that I need to encapsulate the field then to correct the values.

  bool _myBool = false;

  bool get myBool => _myBool;

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

It doesn't help either, as now both the private and public members are deserialized:

GeneralConfiguration _$GeneralConfigurationFromJson(
        Map<String, dynamic> json) =>
    new GeneralConfiguration()
      .._myBool = json['_myBool'] as bool
      ..myBool = json['myBool'] as bool

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions