private void serializeValueComposite( Options options, Object object, OutputType output, boolean rootPass )
throws Exception
{
CompositeInstance valueInstance = Qi4j.FUNCTION_COMPOSITE_INSTANCE_OF.map( (ValueComposite) object );
ValueDescriptor descriptor = (ValueDescriptor) valueInstance.descriptor();
AssociationStateHolder state = (AssociationStateHolder) valueInstance.state();
onObjectStart( output );
if( options.getBoolean( Options.INCLUDE_TYPE_INFO ) && !rootPass )
{
onFieldStart( output, "_type" );
onValueStart( output );
onValue( output, first( descriptor.valueType().types() ).getName() );
onValueEnd( output );
onFieldEnd( output );
}
for( PropertyDescriptor persistentProperty : descriptor.valueType().properties() )
{
Property<?> property = state.propertyFor( persistentProperty.accessor() );
onFieldStart( output, persistentProperty.qualifiedName().name() );
onValueStart( output );
doSerialize( options, property.get(), output, false );
onValueEnd( output );
onFieldEnd( output );
}
for( AssociationDescriptor associationDescriptor : descriptor.valueType().associations() )
{
Association<?> association = state.associationFor( associationDescriptor.accessor() );
Object instance = association.get();
onFieldStart( output, associationDescriptor.qualifiedName().name() );
onValueStart( output );
if( instance == null )
{
onValue( output, null );
}
else
{
onValue( output, ( (Identity) instance ).identity().get() );
}
onValueEnd( output );
onFieldEnd( output );
}
for( AssociationDescriptor associationDescriptor : descriptor.valueType().manyAssociations() )
{
ManyAssociation<?> manyAssociation = state.manyAssociationFor( associationDescriptor.accessor() );
onFieldStart( output, associationDescriptor.qualifiedName().name() );
onValueStart( output );
onArrayStart( output );
for( Object instance : manyAssociation )
{
onValueStart( output );
onValue( output, ( (Identity) instance ).identity().get() );
onValueEnd( output );
}
onArrayEnd( output );
onValueEnd( output );
onFieldEnd( output );
}
for( AssociationDescriptor associationDescriptor : descriptor.valueType().namedAssociations() )
{
NamedAssociation<?> namedAssociation = state.namedAssociationFor( associationDescriptor.accessor() );
onFieldStart( output, associationDescriptor.qualifiedName().name() );
onValueStart( output );
onObjectStart( output );