Skip to content

Incorrect JSON deserialization in handleOneWayDeviceRPCRequestV2WithHttpInfo #74

Description

@aw4github

Using ThingsBoard CE 4.3.1.3 with thingsboard-client-ce 4.3.1.3, an exception occurs in the generated client method:

handleOneWayDeviceRPCRequestV2WithHttpInfo

Exception

com.fasterxml.jackson.databind.exc.MismatchedInputException:
Cannot deserialize value of type `java.lang.String` from Object value
(token `JsonToken.START_OBJECT`)

Cause

The response body is a JSON object containing the rpcId, but the client attempts to deserialize the entire response directly into a String:

String responseValue = responseBody.isBlank()
        ? null
        : memberVarObjectMapper.readValue(
                responseBody,
                new TypeReference<String>() {}
          );

return new ApiResponse<String>(
        localVarResponse.statusCode(),
        localVarResponse.headers().map(),
        responseValue
);

This fails when the API response is an object such as:

{
  "rpcId": "..."
}

Proposed fix

Extract the rpcId field from the JSON response instead:

String responseValue = responseBody.isBlank()
        ? null
        : memberVarObjectMapper.readTree(responseBody).get("rpcId").asText();

return new ApiResponse<String>(
        localVarResponse.statusCode(),
        localVarResponse.headers().map(),
        responseValue
);

This correctly handles the object response and returns the rpcId as the expected String.

Expected result

handleOneWayDeviceRPCRequestV2WithHttpInfo should successfully deserialize the RPC response and return the rpcId without throwing MismatchedInputException.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions