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

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

    Details

    • Subcomponent:
    • Resolved In Build:
      b06
    • Verification:
      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

              • Assignee:
                dfuchs Daniel Fuchs
                Reporter:
                dfuchs Daniel Fuchs
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: