public static Object byteBufToGenericObject(ByteBuf input, ObjectMapper mapper) throws IOException {
        //skip leading whitespaces
        int toSkip = input.forEachByte(new WhitespaceSkipper());
        if (toSkip > 0) {
            input.skipBytes(toSkip);
        }
        //peek into the buffer for quick detection of objects and arrays
        input.markReaderIndex();
        byte first = input.readByte();
        input.resetReaderIndex();

        switch (first) {
            case '{':
                return byteBufToClass(input, JsonObject.class, mapper);
            case '[':
                return byteBufToClass(input, JsonArray.class, mapper);
        }

        //we couldn't fast detect the type, we'll have to unmarshall to object and make sure maps and lists
        //are converted to JsonObject/JsonArray.
        Object value = byteBufToClass(input, Object.class, mapper);
        if (value instanceof Map) {
            LOGGER.warn(
              "A JSON object could not be fast detected (first byte '{}')",
              user((char) first)
            );
            return JsonObject.from((Map<String, ?>) value);
        } else if (value instanceof List) {
            LOGGER.warn(
              "A JSON array could not be fast detected (first byte '{}')",
              user((char) first)
            );
            return JsonArray.from((List<?>) value);
        } else {
            return value;
        }
    }
public static Object byteBufToGenericObject ( ByteBuf input , ObjectMapper mapper ) throws IOException { int toSkip = input . forEachByte ( new WhitespaceSkipper ( ) ) ; if ( toSkip > 0 ) { input . skipBytes ( toSkip ) ; } input . markReaderIndex ( ) ; byte first = input . readByte ( ) ; input . resetReaderIndex ( ) ; switch ( first ) { case '{' : return byteBufToClass ( input , JsonObject . class , mapper ) ; case '[' : return byteBufToClass ( input , JsonArray . class , mapper ) ; } Object value = byteBufToClass ( input , Object . class , mapper ) ; if ( value instanceof Map ) { LOGGER . warn ( "A JSON object could not be fast detected (first byte '{}')" , user ( ( char ) first ) ) ; return JsonObject . from ( ( Map < String , ? > ) value ) ; } else if ( value instanceof List ) { LOGGER . warn ( "A JSON array could not be fast detected (first byte '{}')" , user ( ( char ) first ) ) ; return JsonArray . from ( ( List < ? > ) value ) ; } else { return value ; } }
Converts a {@link ByteBuf} representing a valid JSON entity to a generic {@link Object},
<b>without releasing the buffer</b>. The entity can either be a JSON object, array or scalar value,
potentially with leading whitespace (which gets ignored). JSON objects are converted to a {@link JsonObject}
and JSON arrays to a {@link JsonArray}.

Detection of JSON objects and arrays is attempted in order not to incur an
additional conversion step (JSON to Map to JsonObject for example), but if a
Map or List is produced, it will be transformed to {@link JsonObject} or
{@link JsonArray} (with a warning logged).

@param input the buffer to convert. It won't be released.
@return a Object decoded from the buffer
@throws IOException if the decoding fails.