question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for properties with capital letter on second place

See original GitHub issue

The mapper creates property names from the get- or set-method transforming the first letter to lower case.

static String toPropertyName(Method method) {
    String name = method.getName();
    if (isBoolGetter(method)) {
      return firstCharacterToLowerCase(name.substring(2, name.length()));
    } else {
      if (isGetterOrSetter(method)) {
        return firstCharacterToLowerCase(name.substring(3, name.length()));
      } else {
        throw new IllegalArgumentException("The specified method is neither a getter nor a setter method.");
      }
    }
  }

In case of properties like ‘aProp’ with a getter ‘getAProp’ the PropertyDescripter does not convert the first character to lower case. The rule is no conversion, if the first two characters of the name are both uppercase. So the mapper failed getting the PropertyDescripter because of no matching property name and the property will be marked as invalid java bean property.

  static PropertyDescriptor getPropertyDescriptorOrFail(Target target, Class<?> type, String propertyName) {
    Optional<PropertyDescriptor> property;
    property = Properties.getProperties(type, target)
        .stream()
        .filter(pd -> pd.getName()
            .equals(propertyName))
        .findFirst();
    if (property.isPresent()) {
      return property.get();
    } else {
      throw notAProperty(type, propertyName);
    }
  }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
buschmdcommented, Dec 27, 2018

It’s part of the JavaBean Specification. Here is the some extract:

8.8 Capitalization of inferred names. When we use design patterns to infer a property or event name, we need to decide what rules to follow for capitalizing the inferred name. If we extract the name from the middle of a normal mixedCase style Java name then the name will, by default, begin with a capital letter. Java programmers are accustomed to having normal identifiers start with lower case letters. Vigorous reviewer input has convinced us that we should follow this same conventional rule for property and event names.

Thus when we extract a property or event name from the middle of an existing Java name, we normally convert the first character to lower case. However to support the occasional use of all upper-case names, we check if the first two characters of the name are both upper case and if so leave it alone. So for example, “FooBah” becomes “fooBah” “Z” becomes “z” “URL” becomes “URL” We provide a method Introspector.decapitalize which implements this conversion rule.

https://download.oracle.com/otndocs/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/

0reactions
buschmdcommented, Jan 7, 2019

Perfect, thanks for the quick implementation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does Jackson 2 not recognize the first capital letter if the ...
This does help. Curious though, in the Java Bean spec 8.8, they actually mention if the first two letter are uppercase they leave...
Read more >
text-transform - CSS: Cascading Style Sheets - MDN Web Docs
The text-transform CSS property specifies how to capitalize an element's text. It can be used to make text appear in all-uppercase or ...
Read more >
Capitalization Conventions - Framework Design Guidelines
Apply capitalization conventions for identifiers, compound words, and common terms. Understand how case sensitivity works in .NET.
Read more >
Change lombok's property capitalization code. `Field xName ...
[BUG] When the first letter of an attribute is lowercase and the second letter is uppercase, the getter and setter methods generated by ......
Read more >
Capitalization of Job Titles
The standard about capitalizing prepositions of four (or five) letters or more in composition titles is pretty widespread, I believe. It is the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found