Azure / Azure/azure-iot-service-sdk-java

Direct Method response JSON object payload with a null value is returned as an empty JSON object

Open
#41 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
5
Forks
14
PR merge metrics
No merged PRs in 30d

Description

# Context

- **Java runtime used:** `Amazon Corretto-21.0.4.7.1 (build 21.0.4+7-LTS)`
- **SDK version used:** `com.microsoft.azure.sdk.iot:iot-service-client:2.1.9`

## Description of the issue
We are invoking a Direct Method on an Azure IoT Edge device. The edge device is returning a response payload with the following JSON payload:
`{ "result": null }`

When the direct method was invoked using the 1.x version of the IoT Service Client, we received the the payload as expected ( a JSON object with a single key named "result" whose value was null). After we updated the IoT Service Client to version 2.1.9, we started being returned a empty JSON Object.

## Code sample exhibiting the issue

Sample code (with 2.x version) sending the direct method:

```
Logger logger = LoggerFactory.getLogger("testlogger");

DirectMethodsClient directMethodsClient = new DirectMethodsClient("connection string");

Object payload = Collections.emptyMap();
DirectMethodRequestOptions directMethodRequestOptions = DirectMethodRequestOptions.builder()
.payload(payload)
.methodConnectTimeoutSeconds(30)
.methodResponseTimeoutSeconds(30)
.build();

String deviceId = "some device ID";
String moduleId = "some module ID";
String methodName = "directMethodName";
DirectMethodResponse result = directMethodsClient.invoke(deviceId, moduleId, methodName, directMethodRequestOptions);

logger.debug("MethodResult: status={}, payload={}", result.getStatus(), result.getPayloadAsJsonElement());
```

## Console log of the issue
We would have expected to received:

> MethodResult: status=200, payload={"result":null}

but we actually receive:

> MethodResult: status=200, payload={}

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.