emitter.emit(Event.SEQUENCE_END);
return;
}
if (object instanceof Map) {
emitter.emit(new MappingStartEvent(anchor, tag, !showTag, false));
for (Object item : ((Map)object).entrySet()) {
Entry entry = (Entry)item;
writeValue(entry.getKey(), null, null, null);
if (isRoot && !config.writeConfig.writeRootElementTags) elementType = entry.getValue().getClass();
writeValue(entry.getValue(), elementType, null, null);
}
emitter.emit(Event.MAPPING_END);
return;
}
if (fieldClass.isArray()) {
elementType = fieldClass.getComponentType();
emitter.emit(new SequenceStartEvent(anchor, null, true, false));
for (int i = 0, n = Array.getLength(object); i < n; i++)
writeValue(Array.get(object, i), elementType, null, null);
emitter.emit(Event.SEQUENCE_END);
return;
}
// Value must be a bean.
Object prototype = null;
if (!config.writeConfig.writeDefaultValues && valueClass != Class.class) {
prototype = defaultValuePrototypes.get(valueClass);
if (prototype == null && Beans.getDeferredConstruction(valueClass, config) == null) {
try {
prototype = Beans.createObject(valueClass, config.privateConstructors);
} catch (InvocationTargetException ex) {
throw new YamlException("Error creating object prototype to determine default values.", ex);
}
defaultValuePrototypes.put(valueClass, prototype);
}
}
Set<Property> properties;
try {
properties = Beans.getProperties(valueClass, config.beanProperties, config.privateFields, config);
} catch (IntrospectionException ex) {
throw new YamlException("Error inspecting class: " + valueClass.getName(), ex);
}
emitter.emit(new MappingStartEvent(anchor, tag, !showTag, false));
for (Property property : properties) {
try {
Object propertyValue = property.get(object);
if (prototype != null) {
// Don't output properties that have the default value for the prototype.