Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter json_serializable use JsonValue as the json key of Enum #713

Open
whlsxl opened this issue May 11, 2024 · 0 comments
Open

Flutter json_serializable use JsonValue as the json key of Enum #713

whlsxl opened this issue May 11, 2024 · 0 comments

Comments

@whlsxl
Copy link

whlsxl commented May 11, 2024

Which packages are impacted by your issue?

@graphql-codegen/flutter-freezed

Describe the bug

The current version of json_serializable uses JsonValue as the Enum json serialize key.

Your Example Website or App

https://stackblitz.com/edit/github-mc3hpg?file=app_models.dart

Steps to Reproduce the Bug or Issue

Schema.graphql

enum BookCategory {
  BusinessCareer
  Family
}

Generate

enum BookCategory {
  @JsonKey(name: 'BusinessCareer')
  businessCareer,
  @JsonKey(name: 'Family')
  family,
}

freezed generate


const _$BookCategoryEnumMap = {
  BookCategory.businessCareer: 'businessCareer',
  BookCategory.family: 'family',
}

freezed use $enumDecode(_$BookCategoryEnumMap, e); to trans from json.

got error

Invalid argument(s): `BusinessCareer` is not one of the supported values: businessCareer, family,

Expected behavior

enum BookCategory {
  @JsonValue('BusinessCareer')
  businessCareer,
  @JsonValue('Family')
  family,
}

Screenshots or Videos

No response

Platform

    "@graphql-codegen/cli": "5.0.2",
    "@graphql-codegen/flutter-freezed": "^4.0.0",
    "@graphql-codegen/introspection": "4.0.3",
    "@graphql-codegen/typescript": "4.0.6",
    "@graphql-codegen/typescript-resolvers": "4.0.6",

Codegen Config File

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant