public static String toCamelCase ( String str ) { if ( str == null || str . isEmpty ( ) ) { return str ; } StringBuilder stringBuilder = new StringBuilder ( ) ; boolean foundFirstLowercase = false ; for ( char cur : str . toCharArray ( ) ) { if ( Character . isUpperCase ( cur ) && ! foundFirstLowercase ) { stringBuilder . append ( Character . toLowerCase ( cur ) ) ; } else { foundFirstLowercase = true ; stringBuilder . append ( cur ) ; } } return stringBuilder . toString ( ) ; }
This matches the algorithm that Jackson uses to convert getter names to JSON field names . Any names starting with a lowercase character are left as is any names starting with one or more uppercase characters have all consecutive uppercase characters converted to lowercase . See tests for examples .