Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lombok build getters/setters not by standard Java Beans specification #1661

Closed
jsbxyyx opened this issue Apr 17, 2018 · 4 comments
Closed

lombok build getters/setters not by standard Java Beans specification #1661

jsbxyyx opened this issue Apr 17, 2018 · 4 comments

Comments

@jsbxyyx
Copy link

jsbxyyx commented Apr 17, 2018

question

lombok version: lastest
lombok build getters/setters not by standard Java Beans specification

code

standard java beans getter/setter

public class A {
private String vNum;
public void setvNum(String vNum) {
    this.vNum=vNum;
}
public String getvNum() {
    return vNum;
}
}

lombok getter/setter (decoder result)

public class A {
private String vNum;
public void setVNum(String vNum) {
    this.vNum=vNum;
}
public String getVNum() {
    return vNum;
}
}

resolve

you can use Introspector.decapitalize(name) get property

@victorwss
Copy link
Contributor

Seems to be another dupe in the pile: #757, #1593, #1496, #1453, #1454.

@rspilker
Copy link
Collaborator

There are conflicting implementations, even in java.beans.

  • java.beans.NameGenerator.capitalize
    public static String capitalize(String name) {
        if (name == null || name.length() == 0) {
            return name;
        }
        return name.substring(0, 1).toUpperCase(ENGLISH) + name.substring(1);
    }
  • java.beans.PropertyDescriptor (constructor uses NameGenerator)
  • Introspector.decapitalize
    public static String decapitalize(String name) {
        if (name == null || name.length() == 0) {
            return name;
        }
        if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) &&
                        Character.isUpperCase(name.charAt(0))){
            return name;
        }
        char chars[] = name.toCharArray();
        chars[0] = Character.toLowerCase(chars[0]);
        return new String(chars);
    }

If we would have started lombok right now we might have made a different choice.

@xxzkid
Copy link

xxzkid commented Apr 27, 2018

@rspilker
most open sources frameworks use Introspector.decapitalize(name) method build java beans
example: spring, dozer, jackson etc...

@rzwitserloot
Copy link
Collaborator

Duplicate of #2693

@rzwitserloot rzwitserloot marked this as a duplicate of #2693 Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants