json_serializable.dart icon indicating copy to clipboard operation
json_serializable.dart copied to clipboard

Add an option to create the reversed enum map

Open ValentinVignal opened this issue 1 year ago • 0 comments

It would be very useful to create a reversed enum map:

@JsonEnum()
enum MyEnum {
  a,
  b,
}

What is currently generated:

const _$MobileScreenNameEnumMap = {
  MyEnum.a: 'a',
  MyEnum.b: 'b',
};

It would be very useful to generate:

const _$MobileScreenNameEnumMapFromNames = { // Or whatever better name.
  'a': MyEnum.a,
  'b': MyEnum.b,
};

With maybe some assertions when generating that check the json keys are all unique

ValentinVignal avatar Aug 11 '22 09:08 ValentinVignal