/** * Gets the value of the field in the given instance as String. * Currently only allows primitive types, boxed types, String and Enum. */ private String getStringValue(Object instance, Field field) throws IllegalAccessException { Class<?> fieldType = field.getType(); // Only support primitive type, boxed type, String and Enum if (!fieldType.isPrimitive() && !Primitives.isWrapperType(fieldType) && !String.class.equals(fieldType) && !fieldType.isEnum()) { throw new IllegalArgumentException( String.format("Unsupported property type %s of field %s in class %s.", fieldType.getName(), field.getName(), field.getDeclaringClass().getName())); } if (!field.isAccessible()) { field.setAccessible(true); } Object value = field.get(instance); if (value == null) { return null; } // Key name is "className.fieldName". return fieldType.isEnum() ? ((Enum<?>) value).name() : value.toString(); } }
|| typeAdapter instanceof InstanceCreator<?> || typeAdapter instanceof TypeAdapter<?>); if (Primitives.isPrimitive(type) || Primitives.isWrapperType(type)) { throw new IllegalArgumentException( "Cannot register type adapters for " + type);