Java tutorial
//package com.java2s; import com.fasterxml.jackson.databind.introspect.AnnotatedMethod; public class Main { public static String okNameForSetter(AnnotatedMethod am) { String name = okNameForMutator(am, "set"); if (name != null) { // 26-Nov-2009 [JACSON-103], need to suppress this internal groovy method if ("metaClass".equals(name)) { if (isGroovyMetaClassSetter(am)) { return null; } } return name; } return null; } public static String okNameForMutator(AnnotatedMethod am, String prefix) { String name = am.getName(); if (name.startsWith(prefix)) { return manglePropertyName(name.substring(prefix.length())); } return null; } /** * Similar to {@link #isCglibGetCallbacks}, need to suppress * a cyclic reference to resolve [JACKSON-103] */ protected static boolean isGroovyMetaClassSetter(AnnotatedMethod am) { Class<?> argType = am.getRawParameterType(0); Package pkg = argType.getPackage(); if (pkg != null && pkg.getName().startsWith("groovy.lang")) { return true; } return false; } /** * Method called to figure out name of the property, given * corresponding suggested name based on a method or field name. * * @param basename Name of accessor/mutator method, not including prefix * ("get"/"is"/"set") */ protected static String manglePropertyName(String basename) { int len = basename.length(); // First things first: empty basename is no good if (len == 0) { return null; } // otherwise, lower case initial chars StringBuilder sb = null; for (int i = 0; i < len; ++i) { char upper = basename.charAt(i); char lower = Character.toLowerCase(upper); if (upper == lower) { break; } if (sb == null) { sb = new StringBuilder(basename); } sb.setCharAt(i, lower); } return (sb == null) ? basename : sb.toString(); } }