@Test public void testRequiresPathHeaderQueryAnnotation() throws Exception { assertThat(factory.stringConverter(java.util.Optional.class, createAnnotations(Header.class), null)) .isNotNull(); assertThat(factory.stringConverter(java.util.Optional.class, createAnnotations(Path.class), null)) .isNotNull(); assertThat(factory.stringConverter(java.util.Optional.class, createAnnotations(Query.class), null)) .isNotNull(); assertThat(factory.stringConverter(java.util.Optional.class, createAnnotations(Nonnull.class), null)) .isNull(); assertThat(factory.stringConverter(java.util.OptionalInt.class, createAnnotations(Header.class), null)) .isNotNull(); assertThat(factory.stringConverter(java.util.OptionalInt.class, createAnnotations(Path.class), null)) .isNotNull(); assertThat(factory.stringConverter(java.util.OptionalInt.class, createAnnotations(Query.class), null)) .isNotNull(); assertThat(factory.stringConverter(java.util.OptionalInt.class, createAnnotations(Nonnull.class), null)) .isNull(); assertThat(factory.stringConverter(java.util.OptionalDouble.class, createAnnotations(Header.class), null)) .isNotNull(); assertThat(factory.stringConverter(java.util.OptionalDouble.class, createAnnotations(Path.class), null)) .isNotNull(); assertThat(factory.stringConverter(java.util.OptionalDouble.class, createAnnotations(Query.class), null)) .isNotNull(); assertThat(factory.stringConverter(java.util.OptionalDouble.class, createAnnotations(Nonnull.class), null)) .isNull(); assertThat(factory.stringConverter(java.util.OptionalLong.class, createAnnotations(Header.class), null)) .isNotNull(); assertThat(factory.stringConverter(java.util.OptionalLong.class, createAnnotations(Path.class), null)) .isNotNull(); assertThat(factory.stringConverter(java.util.OptionalLong.class, createAnnotations(Query.class), null)) .isNotNull(); assertThat(factory.stringConverter(java.util.OptionalLong.class, createAnnotations(Nonnull.class), null)) .isNull(); assertThat(factory.stringConverter( com.google.common.base.Optional.class, createAnnotations(Header.class), null)) .isNotNull(); assertThat(factory.stringConverter(com.google.common.base.Optional.class, createAnnotations(Path.class), null)) .isNotNull(); assertThat(factory.stringConverter(com.google.common.base.Optional.class, createAnnotations(Query.class), null)) .isNotNull(); assertThat(factory.stringConverter( com.google.common.base.Optional.class, createAnnotations(Nonnull.class), null)) .isNull(); }
@Override public Converter<?, String> stringConverter(Type type, Annotation[] annotations, Retrofit _retrofit) { Optional<?> pathQueryAnnotation = ImmutableList.copyOf(annotations).stream() .map(Annotation::annotationType) .filter(t -> t == Path.class || t == Query.class || t == Header.class) .findAny(); if (pathQueryAnnotation.isPresent()) { TypeToken<?> typeToken = TypeToken.of(type); Optional<Converter<?, String>> converter = getNullableConverterForRawType(typeToken.getRawType()) .map(conv -> { if (pathQueryAnnotation.get() == Path.class) { @SuppressWarnings("unchecked") Converter<Object, String> castConverter = (Converter<Object, String>) conv; return val -> Optional.ofNullable(castConverter.convert(val)) .orElse(""); } else { return conv; } }); return converter.orElse(null); } return null; }
OptionalObjectToStringConverterFactory extends Converter.Factory { @Override public Converter<?, String> stringConverter(Type type, Annotation[] annotations, Retrofit _retrofit) { Optional<?> pathQueryAnnotation = ImmutableList.copyOf(annotations).stream() .map(Annotation::annotationType) .filter(t -> t == Path.class || t == Query.class || t == Header.class) .findAny(); if (pathQueryAnnotation.isPresent()) { TypeToken<?> typeToken = TypeToken.of(type); Optional<Converter<?, String>> converter = getNullableConverterForRawType(typeToken.getRawType()) .map(conv -> { if (pathQueryAnnotation.get() == Path.class) { @SuppressWarnings("unchecked") Converter<Object, String> castConverter = (Converter<Object, String>) conv; return val -> Optional.ofNullable(castConverter.convert(val)) .orElse(""); } else { return conv; } }); return converter.orElse(null); } return null; } }
OptionalObjectToStringConverterFactory extends Converter.Factory { @Override public Converter<?, String> stringConverter(Type type, Annotation[] annotations, Retrofit _retrofit) { Optional<?> pathQueryAnnotation = ImmutableList.copyOf(annotations).stream() .map(Annotation::annotationType) .filter(t -> t == Path.class || t == Query.class || t == Header.class) .findAny(); if (pathQueryAnnotation.isPresent()) { TypeToken<?> typeToken = TypeToken.of(type); Optional<Converter<?, String>> converter = getNullableConverterForRawType(typeToken.getRawType()) .map(conv -> { if (pathQueryAnnotation.get() == Path.class) { @SuppressWarnings("unchecked") Converter<Object, String> castConverter = (Converter<Object, String>) conv; return val -> Optional.ofNullable(castConverter.convert(val)) .orElse(""); } else { return conv; } }); return converter.orElse(null); } return null; } private  OptionalObjectToStringConverterFactory(); }
OptionalObjectToStringConverterFactory extends Converter.Factory { @Override public Converter<?, String> stringConverter(Type type, Annotation[] annotations, Retrofit _retrofit) { Optional<?> pathQueryAnnotation = ImmutableList.copyOf(annotations).stream() .map(Annotation::annotationType) .filter(t -> t == Path.class || t == Query.class || t == Header.class) .findAny(); if (pathQueryAnnotation.isPresent()) { TypeToken<?> typeToken = TypeToken.of(type); Optional<Converter<?, String>> converter = getNullableConverterForRawType(typeToken.getRawType()) .map(conv -> { if (pathQueryAnnotation.get() == Path.class) { @SuppressWarnings("unchecked") Converter<Object, String> castConverter = (Converter<Object, String>) conv; return val -> Optional.ofNullable(castConverter.convert(val)) .orElse(""); } else { return conv; } }); return converter.orElse(null); } return null; } private  OptionalObjectToStringConverterFactory(); @Override Converter<?, String> stringConverter(Type type, Annotation[] annotations, Retrofit _retrofit); }
OptionalObjectToStringConverterFactory extends Converter.Factory { @Override public Converter<?, String> stringConverter(Type type, Annotation[] annotations, Retrofit _retrofit) { Optional<?> pathQueryAnnotation = ImmutableList.copyOf(annotations).stream() .map(Annotation::annotationType) .filter(t -> t == Path.class || t == Query.class || t == Header.class) .findAny(); if (pathQueryAnnotation.isPresent()) { TypeToken<?> typeToken = TypeToken.of(type); Optional<Converter<?, String>> converter = getNullableConverterForRawType(typeToken.getRawType()) .map(conv -> { if (pathQueryAnnotation.get() == Path.class) { @SuppressWarnings("unchecked") Converter<Object, String> castConverter = (Converter<Object, String>) conv; return val -> Optional.ofNullable(castConverter.convert(val)) .orElse(""); } else { return conv; } }); return converter.orElse(null); } return null; } private  OptionalObjectToStringConverterFactory(); @Override Converter<?, String> stringConverter(Type type, Annotation[] annotations, Retrofit _retrofit); static final OptionalObjectToStringConverterFactory INSTANCE; }