5

I have a problem with generating getter/setter for attributes like xPos, yPos, nCounter and so on. Plattform is Eclipse Luna, Java 1.7, Struts2...

While Eclipse generates

private xPos

getXPos()
setXPos(...)

Lombok will generate

getxPos()
setxPos(...)

Is there any way to tell Lombok to uppercase every first character?

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
AnJu
  • 51
  • 1
  • 3
  • 1
    Lombok makes the first character uppercase: https://projectlombok.org/features/GetterSetter.html . The problem should be somewhere else. – rics Oct 12 '16 at 08:02
  • Yes, but only if there at least two chars before the first uppercase char. – AnJu Oct 12 '16 at 08:47
  • "For generating the method names, the first character of the field, if it is a lowercase character, is title-cased, otherwise, it is left unmodified. Then, get/set/is is prefixed." No mention of your "two chars" rule. @Getter int xPos; generates getXPos() for me as expected. – rics Oct 12 '16 at 09:51
  • Lombok now generates it correct. Had in the meantime manually written the setter to become ready. Now I wanted to take another a look to this behaviour and now it works... – AnJu Oct 12 '16 at 12:19
  • intellij as well will generate getxPos(), it's not a problem – Daniel Taub Jan 05 '18 at 18:00
  • I encountered a post here --> https://stackoverflow.com/questions/43503977/spring-mvc-jackson-mapping-query-parameters-to-modelattribute-lowercase-wi, if the problem is jackson mapper/marshaller of the rest api, try using @JsonProperty("xPos") annotation on the field. It fixed my issue. – Artanis Zeratul Aug 19 '19 at 09:47

1 Answers1

3

Even if the getter looks OK , you may need to force property name when this class is sent over the wire and converted to json for it

 @Setter(onMethod_ = {@JsonSetter("yResolution")})
 @Getter(onMethod_ = {@JsonGetter("yResolution")})
 private String yResolution;
 

Without this metadata the json string that will be created will be with all lower case letters

Found it here Custom serialized and deserialized field names with lombok

Maayan Hope
  • 1,482
  • 17
  • 32