code: public static <T> void writeNullableCollection(Collection<T> items, ObjectDataOutput out) throws IOException {
          // write true when the collection is NOT null
          out.writeBoolean(items != null);
          if (items == null) {
              return;
          }
          writeCollection(items, out);
      }
docs: Writes a collection to an {@link ObjectDataOutput}. The collection's size is written
  to the data output, then each object in the collection is serialized.
  The collection is allowed to be null.
  
  @param items collection of items to be serialized
  @param out   data output to write to
  @param <T>   type of items
  @throws IOException when an error occurs while writing to the output