}
public void addDelegatingSerializerToConstructor( @Nonnull JDefinedClass serializerClass, @Nonnull JClass fieldType ) {
JType fieldSerializerType = getSerializerRefFor( fieldType );
JMethod constructor = ( JMethod ) serializerClass.constructors().next();
String paramName = NamingSupport.createVarName( fieldSerializerType.name() );
//Check whether the serializer still exists
for ( JVar param : constructor.listParams() ) {
if ( param.type().equals( fieldSerializerType ) ) {
return;
}
}
//It does not exist, therefore let us add the serializer and map it
JVar param = constructor.param( fieldSerializerType, paramName );
constructor.body().add( JExpr.invoke( "add" ).arg( param ).invoke( "responsibleFor" ).arg( JExpr.dotclass( fieldType ) )
.invoke( "map" )
.arg( JExpr.lit( 1 ) ).arg( JExpr.lit( 0 ) ).arg( JExpr.lit( 0 ) )
.invoke( "toDelegateVersion" )
.arg( JExpr.lit( 1 ) ).arg( JExpr.lit( 0 ) ).arg( JExpr.lit( 0 ) ) );
}