private static boolean isOptional(TypeMirror type) {
    if (type.getKind() != TypeKind.DECLARED) {
      return false;
    }

    return MoreTypes.asTypeElement(type).getQualifiedName().contentEquals("java.util.Optional");
  }
Checks if the given type is an {@link Optional}.
value/src/main/java/com/google/auto/value/extension/serializable/serializer/impl/OptionalSerializerExtension.java