Search code examples
flutterflutter-freezed

Flutter freezed - what is @JsonValue for


I see you can do, for example

factory User({
  @JsonKey(name: 'home_address') String? homeAddress,
  @JsonKey(name: 'first_name') String firstName,
})

and the keys home_address and first_name from a json will be the properties homeAddress and firstName respectively.

But what is @JsonValue used for then?


Solution

  • It is used to serialize/deserialize an enum instance, as stated in the documentation.

    For an example see here.