Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8217264

HttpClient: Blocking operations in mapper function do not work as documented

XMLWordPrintable

    • b06
    • Verified

      The javadoc example for HttpResponse.BodySubscribers::mapping will wedge the response waiting for MappingSubscribers.getBody() to complete:

        public static <W> BodySubscriber<W> asJSON(Class<W> targetType) {
           BodySubscriber<InputStream> upstream = BodySubscribers.ofInputStream();

           BodySubscriber<W> downstream = BodySubscribers.mapping(
                 upstream,
                 (InputStream is) -> {
                     try (InputStream stream = is) {
                         ObjectMapper objectMapper = new ObjectMapper();
                         return objectMapper.readValue(stream, targetType);
                     } catch (IOException e) {
                         throw new UncheckedIOException(e);
                     }
                 });
          return downstream;
       } }

            dfuchs Daniel Fuchs
            dfuchs Daniel Fuchs
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: