java - not - lombok override getter - Code Examples

文章推薦指數: 80 %
投票人數:10人

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



請為這篇文章評分?