Я пытаюсь выполнить кеширование с использованием reactor
, reactor.ipc.netty.http.client.HttpClient
и инициализировать его как ленивое поле получения с помощью lombok @Getter(lazy = true)
.
Все отлично работает с Java 8, но не может скомпилироваться с error: incompatible types: Duration cannot be converted to String
с Java 10 по этому фрагменту
@Value
public static class Translations {
Map<String, Translation> translations;
@Value
public static class Translation {
Map<String, String> content;
}
}
@Getter(lazy = true)
Mono<Map<String, Translations.Translation>> translations = httpClient
.get(String.format("%s/translations/%s", endpoint, translationGroup), Function.identity())
.flatMap(it -> it.receive().aggregate().asByteArray())
.map(byteArray -> {
try {
return objectMapper.readValue(byteArray, Translations.class);
} catch (IOException e) {
throw new UncheckedIOException("Failed to get translation for " + translationGroup, e);
}
})
.map(Translations::getTranslations)
.retryWhen(it -> it.delayElements(Duration.ofMillis(200)))
.cache(Duration.ofMinutes(5))
.timeout(Duration.ofSeconds(10));
но он прекрасно компилируется с
@Getter(lazy = true)
Mono<Map<String, Translations.Translation>> translations = Mono.just(new byte[]{})
.map(byteArray -> {
try {
return objectMapper.readValue(byteArray, Translations.class);
} catch (IOException e) {
throw new UncheckedIOException("Failed to get translation for " + translationGroup, e);
}
})
.map(Translations::getTranslations)
.retryWhen(it -> it.delayElements(Duration.ofMillis(200)))
.cache(Duration.ofMinutes(5))
.timeout(Duration.ofSeconds(10));
Как узнать, что не так и как это можно обойти?