private static Set<String> duplicateFields(Class cls){
  Set<String> all=new HashSet<>();
  Set<String> duplicates=new HashSet<>();
  for (Class<?> c=cls; c != null && !c.equals(Object.class); c=c.getSuperclass()) {
    for (    Field f : c.getDeclaredFields()) {
      if (serializeField(f)) {
        String name=f.getName();
        if (!all.add(name))         duplicates.add(name);
      }
    }
  }
  return duplicates;
}

private static Set < String > duplicateFields ( Class cls ) { Set < String > all = new HashSet < > ( ) ; Set < String > duplicates = new HashSet < > ( ) ; for ( Class < ? > c = cls ; c != null && ! c . equals ( Object . class ) ; c = c . getSuperclass ( ) ) { for ( Field f : c . getDeclaredFields ( ) ) { if ( serializeField ( f ) ) { String name = f . getName ( ) ; if ( ! all . add ( name ) ) duplicates . add ( name ) ; } } } return duplicates ; }
find all fields with duplicate names in the class .
