private static SortedSet<Field> getFields(Class<?> clazz, SerializerConfig config) {
        TreeSet<Field> set = new TreeSet<Field>(new FieldComparator());
        for (Field field : clazz.getDeclaredFields()) {
            if (!(field.isSynthetic() || Modifier.isStatic(field.getModifiers()))) {
                field.setAccessible(true);
                config.register(field.getType());
                set.add(field);
            }
        }
        if (clazz.getSuperclass() != null && !Object.class.equals(clazz.getSuperclass())) {
            set.addAll(getFields(clazz.getSuperclass(), config));
        }
        return set;
    }