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

Ability to serialize / deserialize boolean properties as numeric values in json #911

Open
cutz opened this issue Aug 19, 2024 · 5 comments

Comments

@cutz
Copy link

cutz commented Aug 19, 2024

Feature description

I have a boolean property that I would like to serialize/deserialize to json as a numeric value 0 or 1. I believe this typically could be done by annotating the property with @JsonFormat(shape=JsonFormat.Shape.Number). As documented micronaut doesn't not support the shape property for JsonFormat and attempts to use it result in the following error:

Annotation @JsonFormat specifies attribute 'shape'. Currently supported attributes include: [timezone, pattern, locale, lenient]

Are there any plans to support this?

@graemerocher
Copy link
Contributor

probably doable yeah

@cutz
Copy link
Author

cutz commented Aug 19, 2024

I don't have a feel for how big of an undertaking this would be. If this seems like something that would be a good starter task, and someone is willing to point me in the right direction, I'd be willing to take a stab at a solution.

@graemerocher
Copy link
Contributor

  1. step 1 is disable the compile time check in JsonFormatMapper by modifying getSupportedMemberNames
  2. Then I guess BooleanSerde would need to be modified to override createSpecific for serialization / deserialization with a specific customised serialised to handle the shape

@dstepanov
Copy link
Contributor

The other solution would be detecting it in the compilation time and and setting a custom serializer/deserializer interface ShapeDeserializer / interface ShapeSerializer + add implementation which would use createSpecific and some logic to do the convertion

@graemerocher
Copy link
Contributor

that would likely be more efficient yes

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

3 participants