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

[FEATURE] @FromEnum(Enum.class) #2397

Closed
Bryksin opened this issue Mar 15, 2020 · 3 comments
Closed

[FEATURE] @FromEnum(Enum.class) #2397

Bryksin opened this issue Mar 15, 2020 · 3 comments

Comments

@Bryksin
Copy link

Bryksin commented Mar 15, 2020

Feature Description
Generated Class with fields based on Enum
This feater request appears from my question in StackOverflow

Basically that feature would allow creating a class with fields from enum class and if @DaTa or @Setter and @getterS are set, mark those fields as privet and generate setters and getter for them

Usage Code prototype:
Definition

public enum JwtFields {
    userId,
    country,
    sessionId,
    anyOtherField
}
@FromEnum(JwtFields.class)
@Data
public class JwtDeserialised {
    private String someAdditionalCutomFieldIfIwant
}

Usage:

String userId = jwtDeserialisedInstance.getUserId(); 
String anyOtherField = jwtDeserialisedInstance.getAnyOtherField();
String someAdditionalCutomFieldIfIwant = jwtDeserialisedInstance.GetSomeAdditionalCutomFieldIfIwant();

Target Audience
Anyone who using Enums as keys to avoid mistyping strings, and later need to deserialise that enum into proper class with sets and gets.

@janrieke
Copy link
Contributor

Why not taking the opposite direction: define your fields in the class and the use @FieldNameConstants(asEnum = true) to generate your enum?

@rzwitserloot
Copy link
Collaborator

We've implemented this, but as @janrieke showed, in the opposite direction: Make the class (and not an enum naming the 'fields').

Note also that the way you want it implemented requires resolution, i.e. is an extremely complex feature.

@Bryksin
Copy link
Author

Bryksin commented Mar 15, 2020

Thank you, guys! Awesome! another way around is also perfectly suited to me!
Didn't spot it in the documentation, but now found in experimental! Very good feature and definitely deserve to be in the main feature rather experimental!

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