code: public static <T> T byteBufToClass(ByteBuf input, Class<? extends T> clazz, ObjectMapper mapper) throws IOException {
          if (input.hasArray()) {
              ByteBufToArray toArray = byteBufToByteArray(input);
              return mapper.readValue(toArray.byteArray, toArray.offset, toArray.length, clazz);
          } else {
              ByteBufInputStream bbis = null;
              try {
                  bbis = new ByteBufInputStream(input);
                  return mapper.readValue((InputStream)bbis, clazz);
              }
              finally {
                  if (bbis != null) {
                      bbis.close();
                  }
              }
          }
      }
docs: Decode a {@link ByteBuf} representing a valid JSON entity to the requested target class,
  using the {@link ObjectMapper} provided and without releasing the buffer.
  
  Mapper uses a {@link ByteBufInputStream} reading directly the netty {@link ByteBuf} if its
  backed by a direct buffer and avoids a memory copy if backed by a heap buffer by using
  the original one with an offset.
  
  @param input the ByteBuf to decode.
  @param clazz the class to decode to.
  @param mapper the mapper to use for decoding.
  @param <T> the decoded type.
  @return the decoded value.
  @throws IOException in case decoding failed.