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.
Why not taking the opposite direction: define your fields in the class and the use @FieldNameConstants(asEnum = true) to generate your enum?
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.
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!
Most helpful comment
Why not taking the opposite direction: define your fields in the class and the use
@FieldNameConstants(asEnum = true)to generate your enum?