in lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/MapMarshaller.java [71:145]
public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
if ( writePossibleNull( value, target ) )
{
Map<?, ?> map = (Map<?, ?>) value;
target.writeInt( map.size() );
Marshaller keyMarshaller = null;
ClassDefinition keyClassDefinition = null;
PropertyDescriptor keyPd = null;
Marshaller valueMarshaller = null;
ClassDefinition valueClassDefinition = null;
PropertyDescriptor valuePd = null;
if ( mapKeyType != null )
{
ensureMarshallersInitialized( serializationContext );
keyMarshaller = mapKeyTypeMarshaller;
Class<?> baseType = TypeUtil.getBaseType( mapKeyType );
keyClassDefinition =
serializationContext.getClassDefinitionContainer().getClassDefinitionByType( baseType );
keyPd =
new CheatPropertyDescriptor( propertyDescriptor.getPropertyName() + "Key", baseType, keyMarshaller );
valueMarshaller = mapValueTypeMarshaller;
baseType = TypeUtil.getBaseType( mapValueType );
valueClassDefinition =
serializationContext.getClassDefinitionContainer().getClassDefinitionByType( baseType );
valuePd =
new CheatPropertyDescriptor( propertyDescriptor.getPropertyName() + "Value", baseType,
valueMarshaller );
}
for ( Entry<?, ?> entry : map.entrySet() )
{
if ( mapKeyType == null )
{
keyMarshaller =
entry.getKey() != null ? serializationContext.findMarshaller( entry.getKey().getClass() )
: null;
keyClassDefinition =
serializationContext.getClassDefinitionContainer().getClassDefinitionByType( entry.getKey().getClass() );
keyPd =
new CheatPropertyDescriptor( propertyDescriptor.getPropertyName() + "Key",
entry.getKey().getClass(), keyMarshaller );
if ( entry.getValue() != null )
{
valueMarshaller =
entry.getValue() != null ? serializationContext.findMarshaller( entry.getValue().getClass() )
: null;
valueClassDefinition =
serializationContext.getClassDefinitionContainer().getClassDefinitionByType( entry.getValue().getClass() );
valuePd =
new CheatPropertyDescriptor( propertyDescriptor.getPropertyName() + "Value",
entry.getValue().getClass(), valueMarshaller );
}
}
if ( writePossibleNull( entry.getKey(), target ) )
{
target.writeLong( keyClassDefinition.getId() );
keyMarshaller.marshall( entry.getKey(), keyPd, target, serializationContext );
}
if ( writePossibleNull( entry.getValue(), target ) )
{
target.writeLong( valueClassDefinition.getId() );
valueMarshaller.marshall( entry.getValue(), valuePd, target, serializationContext );
}
}
}
}