0

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?

user3808307
  • 2,270
  • 9
  • 45
  • 99

1 Answers1

1

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

For an example see here.

yezper
  • 693
  • 3
  • 12
  • So JsonKey to deserialize a class and JsonValue for enums? why are they different – user3808307 May 25 '23 at 13:25
  • 1
    You put JsonKey on a field, whereas you put JsonValue on an enum value to specify how that particular enum value should be serialized to/deserialized from – yezper May 25 '23 at 14:26