code: public static <T extends BasicMessage> BasicMessageWithExtraData<T> fromJSON(InputStream in, Class<T> clazz) {
          final T obj;
          final byte[] remainder;
          try (JsonParser parser = new JsonFactory().configure(Feature.AUTO_CLOSE_SOURCE, false).createParser(in)) {
              Method buildObjectMapperForDeserializationMethod = findBuildObjectMapperForDeserializationMethod(clazz);
  
              final ObjectMapper mapper = (ObjectMapper) buildObjectMapperForDeserializationMethod.invoke(null);
              if (FailOnUnknownProperties.class.isAssignableFrom(clazz)) {
                  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
              }
  
              obj = mapper.readValue(parser, clazz);
              final ByteArrayOutputStream remainderStream = new ByteArrayOutputStream();
              final int released = parser.releaseBuffered(remainderStream);
              remainder = (released > 0) ? remainderStream.toByteArray() : new byte[0];
          } catch (Exception e) {
              throw new IllegalArgumentException("Stream cannot be converted to JSON object of type [" + clazz + "]", e);
          }
          return new BasicMessageWithExtraData<T>(obj, new BinaryData(remainder, in));
      }
docs: Convenience static method that reads a JSON string from the given stream and converts the JSON
  string to a particular message object. The input stream will remain open so the caller can
  stream any extra data that might appear after it.
  
  Because of the way the JSON parser works, some extra data might have been read from the stream
  that wasn't part of the JSON message but was part of the extra data that came with it. Because of this,
  the caller should no longer use the given stream but instead read the extra data via the returned
  object (see {@link BasicMessageWithExtraData#getBinaryData()}) since it will handle this condition
  properly.
  
  @param in input stream that has a JSON string at the head.
  @param clazz the class whose instance is represented by the JSON string
  
  @return a POJO that contains a message object that was represented by the JSON string found
  in the stream. This returned POJO will also contain a {@link BinaryData} object that you
  can use to stream any additional data that came in the given input stream.