src/main/java/ca/jeb/protobuf/ProtobufSerializer.java
private static final void setProtobufFieldValue(ProtobufAttribute protobufAttribute, Builder protoObjBuilder, String setter,
          Object fieldValue) throws NoSuchMethodException, SecurityException, ProtobufAnnotationException, InstantiationException,
          IllegalAccessException, IllegalArgumentException, InvocationTargetException
  {
    Class<? extends Object> fieldValueClass = fieldValue.getClass();
    Class<? extends Object> gpbClass = fieldValueClass;

    final Class<? extends IProtobufConverter> converterClazz = protobufAttribute.converter();
    if (converterClazz != NullConverter.class)
    {
      final IProtobufConverter protoBufConverter = (IProtobufConverter)converterClazz.newInstance();
      fieldValue = protoBufConverter.convertToProtobuf(fieldValue);
      gpbClass = fieldValue.getClass();
      fieldValueClass = gpbClass;
    }

    // Need to convert the argument class from non-primitives to primitives, as Protobuf uses these.
    gpbClass = ProtobufSerializerUtils.getProtobufClass(fieldValue, gpbClass);

    final Method gpbMethod = protoObjBuilder.getClass().getDeclaredMethod(setter, gpbClass);
    gpbMethod.invoke(protoObjBuilder, fieldValue);
  }
private static final void setProtobufFieldValue(ProtobufAttribute protobufAttribute, Builder protoObjBuilder, String setter,
          Object fieldValue) throws NoSuchMethodException, SecurityException, ProtobufAnnotationException, InstantiationException,
          IllegalAccessException, IllegalArgumentException, InvocationTargetException
  {
    Class<? extends Object> fieldValueClass = fieldValue.getClass();
    Class<? extends Object> gpbClass = fieldValueClass;

    final Class<? extends IProtobufConverter> converterClazz = protobufAttribute.converter();
    if (converterClazz != NullConverter.class)
    {
      final IProtobufConverter protoBufConverter = (IProtobufConverter)converterClazz.newInstance();
      fieldValue = protoBufConverter.convertToProtobuf(fieldValue);
      gpbClass = fieldValue.getClass();
      fieldValueClass = gpbClass;
    }

    // Need to convert the argument class from non-primitives to primitives, as Protobuf uses these.
    gpbClass = ProtobufSerializerUtils.getProtobufClass(fieldValue, gpbClass);

    final Method gpbMethod = protoObjBuilder.getClass().getDeclaredMethod(setter, gpbClass);
    gpbMethod.invoke(protoObjBuilder, fieldValue);
  }
private static final void setProtobufFieldValue ( ProtobufAttribute protobufAttribute , Builder protoObjBuilder , String setter , Object fieldValue ) throws NoSuchMethodException , SecurityException , ProtobufAnnotationException , InstantiationException , IllegalAccessException , IllegalArgumentException , InvocationTargetException { Class < ? extends Object > fieldValueClass = fieldValue . getClass ( ) ; Class < ? extends Object > gpbClass = fieldValueClass ; final Class < ? extends IProtobufConverter > converterClazz = protobufAttribute . converter ( ) ; if ( converterClazz != NullConverter . class ) { final IProtobufConverter protoBufConverter = ( IProtobufConverter ) converterClazz . newInstance ( ) ; fieldValue = protoBufConverter . convertToProtobuf ( fieldValue ) ; gpbClass = fieldValue . getClass ( ) ; fieldValueClass = gpbClass ; } // Need to convert the argument class from non-primitives to primitives, as Protobuf uses these. gpbClass = ProtobufSerializerUtils . getProtobufClass ( fieldValue , gpbClass ) ; final Method gpbMethod = protoObjBuilder . getClass ( ) . getDeclaredMethod ( setter , gpbClass ) ; gpbMethod . invoke ( protoObjBuilder , fieldValue ) ; }
This method does the actual "set" on the Protobuf builder. If the user specified a converter,
then use that right before we actually try and set the value.

@param protobufAttribute - ProtobufAttribute
@param protoObjBuilder - G.Builder
@param setter - String
@param fieldValue - POJO's filed Object
@throws NoSuchMethodException
@throws SecurityException
@throws ProtobufAnnotationException
@throws InstantiationException
@throws IllegalAccessException
@throws IllegalArgumentException
@throws InvocationTargetException
This method does the actual set on the Protobuf builder . If the user specified a converter then use that right before we actually try and set the value .