}
@Override
public void writeFieldsToStream(final Map<String, Object> fields) {
final Class<?> currentType = currentTypeRef[0];
final ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType);
writer.startNode(ELEMENT_DEFAULT);
for (final String name : fields.keySet()) {
if (!mapper.shouldSerializeMember(currentType, name)) {
continue;
}
final ObjectStreamField field = objectStreamClass.getField(name);
final Object value = fields.get(name);
if (field == null) {
throw new ObjectAccessException("Class "
+ value.getClass().getName()
+ " may not write a field named '"
+ name
+ "'");
}
if (value != null) {
ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(source
.getClass(), name), value.getClass());
if (field.getType() != value.getClass() && !field.getType().isPrimitive()) {
final String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
if (attributeName != null) {
writer.addAttribute(attributeName, mapper.serializedClass(value.getClass()));
}
}
context.convertAnother(value);
writer.endNode();
}
}
writer.endNode();
}
@Override
public void defaultWriteObject() {
boolean writtenDefaultFields = false;
final Class<?> currentType = currentTypeRef[0];
final ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType);
if (objectStreamClass == null) {
return;
}
for (final ObjectStreamField field : objectStreamClass.getFields()) {
final Object value = readField(field, currentType, source);
if (value != null) {
if (!writtenClassWrapper[0]) {
writer.startNode(mapper.serializedClass(currentType));
writtenClassWrapper[0] = true;