{
return null;
}
final Method newBuilderMethod = protoClazz.getMethod("newBuilder");
final Builder protoObjBuilder = (Builder)newBuilderMethod.invoke(null);
for (Entry<Field, ProtobufAttribute> entry : protoBufFields.entrySet())
{
final Field field = entry.getKey();
final ProtobufAttribute gpbAnnotation = entry.getValue();
final String fieldName = field.getName();
// 1. Determine validity of value
Object value = getPojoFieldValue(pojo, gpbAnnotation, field);
// If value is null and it is not required, skip, as the default for Protobuf values is null
if (value == null)
{
continue;
}
// 2. Call recursively if this is a ProtobufEntity
value = serializeToProtobufEntity(value);
// 3. Handle POJO Collections/Lists
if (value instanceof Collection)
{
value = convertCollectionToProtobufs((Collection<Object>)value);
if (((Collection)value).isEmpty())
{
continue;
}
}
// 4. Determine the setter name
final String setter = ProtobufSerializerUtils.getProtobufSetter(gpbAnnotation, field, value);
// 5. Finally, set the value on the Builder
setProtobufFieldValue(gpbAnnotation, protoObjBuilder, setter, value);
}
return protoObjBuilder.build();
}
catch (Exception e)
{
throw new ProtobufException("Could not generate Protobuf object for " + pojo.getClass() + ": " + e, e);