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

An mapper specified for a Enum is not being considered by anotation processor #295

Closed
cvgaviao opened this issue Apr 20, 2020 · 7 comments · Fixed by #341
Closed

An mapper specified for a Enum is not being considered by anotation processor #295

cvgaviao opened this issue Apr 20, 2020 · 7 comments · Fixed by #341
Labels

Comments

@cvgaviao
Copy link
Contributor

Version

4.0.0-SNAPSHOT

Context

Some of my data objects uses a Enum that has a custom constructor. Because of this I've created a converter for it using static methods.
The converter is being mapped using json-mappers.properties.
The DataObject's converter class is being generated, but its fromJson() method is using the generic pattern for the enum:
obj.setMode(org.example.RunMode.valueOf((String)member.getValue()));

Do you have a reproducer?

https://github.com/cvgaviao/vertx-codegen-failing

@vietj
Copy link
Member

vietj commented Aug 28, 2020

@cvgaviao we need to review all these PR's

@cvgaviao cvgaviao mentioned this issue Mar 16, 2021
@vietj
Copy link
Member

vietj commented Mar 22, 2021

as far as I understand you want to map an enum to a string but use your own converter right ?

@vietj
Copy link
Member

vietj commented Mar 22, 2021

and also, this is a use case for service proxies right ?

@cvgaviao
Copy link
Contributor Author

as far as I understand you want to map an enum to a string but use your own converter right ?

Yep, the main necessity was to initially map a string property in a JSON object into a Enum, but those Enums doesn't have a defaut constructor. So, the need for a custom converter to do it.

@vietj
Copy link
Member

vietj commented Mar 22, 2021

it is still not clear because string are mapped to enum using valueOf, not sure what you mean by constructor, can you elaborate ?

@cvgaviao
Copy link
Contributor Author

cvgaviao commented Mar 22, 2021

it is still not clear because string are mapped to enum using valueOf, not sure what you mean by constructor, can you elaborate ?

You can only use valueOf if, and only if, your JSON string property is EXACTLY (including case) equal to the Enum constant.
Will always be situations where the JSON entering in the API server comes from different data sources and using different character case and even format of data.

Take a look in the Enum example that I've added in the PR.

In that enum you can see that a DEV constant can be mapped to development or dev, and ITEST constant can be mapped to itest or integration-test

@vietj
Copy link
Member

vietj commented Mar 22, 2021

that was my question @cvgaviao no worries.

Fyro-Ing pushed a commit to Fyro-Ing/vertx-codegen that referenced this issue Oct 16, 2021
Signed-off-by: Cristiano V. Gavião <[email protected]>
vietj added a commit that referenced this issue Oct 20, 2021
Allow to use custom mapper on Enum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants