Hello
In order to send ditto protocol message I execute:
dittoClient.sendDittoProtocol(Adaptable.newBuilder(TopicPath.newBuilder(ThingId.of(toThingId(device.getThingName())))
.twin()
.commands()
.merge()
.build())
.withPayload(Payload.newBuilder(JsonPointer.of("/features"))
.withValue(org.eclipse.ditto.json.JsonObject.newBuilder()
.set("someKey", someJsonValue)
.build())
.build())
.build())
someJsonValue can be simple value or JsonObject/JsonField.
For simple value it can be created using builder, but what about complex dto objects conversion?
For example if I do:
private JsonField getDesiredProperty(FeatureName featureName, Object valueDto) {
return JsonField.newInstance(featureName.getFeatureName(),
org.eclipse.ditto.json.JsonObject.newBuilder()
.set("desiredProperty", JsonValue.of(gson.toJson(valueDto)))
.build());
}
The issue with JsonValue.of(gson.toJson(valueDto)) is that valueDto is converted as plain String. No internal key/value fields are parsed.
Is there any convenient way to convert java DTO obcect to JsonField/JsonValue?