java - not - lombok override getter - Code Examples
文章推薦指數: 80 %
java - not - lombok override getter. @JsonIgnore with @Getter Annotation (3). Recently i had the same issue using jackson-annotation 2.9.0 and lombok 1.18.2. java-not-lombokoverridegetter @JsonIgnorewith@GetterAnnotation (3) Recentlyihadthesameissueusingjackson-annotation2.9.0andlombok1.18.2 Thisiswhatworkedforme: @Getter @Setter publicclassUser{ @JsonIgnore @JsonProperty(access=JsonProperty.Access.WRITE_ONLY) privateStringpassword; Sobasicallyaddingtheannotation@JsonProperty(access=JsonProperty.Access.WRITE_ONLY)meansthatthepropertymayonlybewrittenfordeserialization(usingsetter)butwillnotbereadonserialization(usinggetter) Caniuse@JsonIgnorewith@Getterannotationfromlombokwithoutexplicitlydefinethegetter,becauseihavetousethisJsonIgnorewhileserializingtheobjectbutwhiledeserializing,theJsonIgnoreannotationmustbeignoresothefieldinmyobjectmustnotbeanull. @Getter @Setter publicclassUser{ privateuserName; @JsonIgnore privatepassword; } iknow,justbydefinetheJsonIgnoreonthegetterofpasswordicanpreventmypasswordtobeserializedbutforthatihavetoexplicitlydefinethegetterthingthatidon'twant. Anyideaplease,Anyhelpwillbeappreciated. ThiscouldbequiteobviousbutIlostalotoftimenotthinkingthissolutionbefore: @Getter @Setter publicclassUser{ privateuserName; @Setter privatepassword; @JsonIgnore publicgetPassword(){returnpassword;} } AsSebastiansaid@__(@JsonIgnore)canresolvethisissuebutsometimestheuseoftheonXLombokfeature(@__())canhaveside-effectsforexamplebreakingthejavadocgeneration. WithJDKversion8usebelow: //@Getter(onMethod=@__({@Id,@Column(name="unique-id")}))//JDK7 //@Setter(onParam=@__(@Max(10000)))//JDK7 @Getter(onMethod_={@Id,@Column(name="unique-id")})//JDK8 @Setter(onParam_=@Max(10000))//JDK8 Source:https://projectlombok.org/features/experimental/onX working not meaning jsonproperty jsonignoreproperties example data annotation java json jackson lombok Whyusegettersandsetters/accessors? IsitsafetouseProjectLombok? What'sthedifferencebetween@Component,@Repository&@ServiceannotationsinSpring? howtospecifyjacksontoonlyusefields-preferablyglobally DifferentnamesofJSONpropertyduringserializationanddeserialization @JsonPropertyannotationonfieldaswellasgetter/setter Ignoringpropertywhendeserializing
延伸文章資訊
- 1[Suggestion] Override Getter/Setter annotations #1026 - GitHub
It would be nice if you would implement overriding getter/setter annotations. For example: @Gette...
- 2Lombok how to customise getter for Boolean object field?
You have two options to override a Getter/Setter in your class. One is the answer from First Opti...
- 3How to override Lombok Setter methods - Java
I'm using lombok in my project and generation Setters and Getters using @Setters and @Getters ann...
- 4@Getter and @Setter - Project Lombok
This lets you override the behaviour of a @Getter , @Setter or @Data annotation on a class. To pu...
- 5史上最全面的Lombok 註解介紹,Look 一下吧!
public class GetterSetterExample { @Getter @Setter private int age = 10; @Setter(AccessLevel.PROT...