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
延伸文章資訊
- 1How do you override a Lombok getter? - QuickAdviser
You can always manually disable getter/setter generation for any field by using the special Acces...
- 2@Getter and @Setter - Project Lombok
This lets you override the behaviour of a @Getter , @Setter or @Data annotation on a class. To pu...
- 3java - not - lombok override getter - Code Examples
java - not - lombok override getter. @JsonIgnore with @Getter Annotation (3). Recently i had the ...
- 4How to override Lombok Setter methods - Java
I'm using lombok in my project and generation Setters and Getters using @Setters and @Getters ann...
- 5Java Code Examples for Getter | Tabnine
RequiredArgsConstructor @Getter. ... Best Java code snippets using lombok.Getter ... getValue(); ...