ObjectMap<String, FieldMetadata> fields = typeToFields.get(type);
if (fields == null) fields = cacheFields(type);
int i = 0;
for (FieldMetadata metadata : new Values<FieldMetadata>(fields)) {
Field field = metadata.field;
try {
Object value = field.get(object);
if (defaultValues != null) {
Object defaultValue = defaultValues[i++];
if (value == null && defaultValue == null) continue;
if (value != null && defaultValue != null && value.equals(defaultValue)) continue;
}
if (debug) System.out.println("Writing field: " + field.getName() + " (" + type.getName() + ")");
writer.name(field.getName());
writeValue(value, field.getType(), metadata.elementType);
} catch (ReflectionException ex) {
throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex);
} catch (SerializationException ex) {
ex.addTrace(field + " (" + type.getName() + ")");
throw ex;
} catch (Exception runtimeEx) {
SerializationException ex = new SerializationException(runtimeEx);