private static final Object convertCollectionToProtobufs ( Collection < Object > collectionOfNonProtobufs ) throws JException { if ( collectionOfNonProtobufs . isEmpty ( ) ) { return collectionOfNonProtobufs ; } final Object first = collectionOfNonProtobufs . toArray ( ) [ 0 ] ; if ( ! ProtobufSerializerUtils . isProtbufEntity ( first ) ) { return collectionOfNonProtobufs ; } final Collection < Object > newCollectionValues ; /** * Maintain the Collection type of value at this stage (if it is a Set), and if conversion is required to a * different Collection type, that will be handled by a converter later on */ if ( collectionOfNonProtobufs instanceof Set ) { newCollectionValues = new HashSet <> ( ) ; } else { newCollectionValues = new ArrayList <> ( ) ; } for ( Object iProtobufGenObj : collectionOfNonProtobufs ) { newCollectionValues . add ( serializeToProtobufEntity ( iProtobufGenObj ) ) ; } return newCollectionValues ; }
Loops through the collection of objects and serializes them iff they have ProtobufEntity annotations .