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

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

    XMLWordPrintable

Details

    • b06
    • Verified

    Description

      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;
       } }

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: