eclipse-ditto/ditto-clients

Thing object not fully populated on change

PaulWojcik-TMMC opened this issue · 1 comments

After the following (example taken from documentation):

client.twin().startConsumption().toCompletableFuture().get(); 
System.out.println("Subscribed for Twin events");
client.twin().registerForThingChanges("my-changes", change -> {
     System.out.println("An existing Thing was modified: " + change.getThing());

The Thing returned from change.getThing() has only fields populated that changed. Other fields like the id, policy or other are null.
There is another method:

change.getValue()

that can be used to find out what changed. I believe the idea for the getThing() was to return a fully populated object that was affected by the change.

The getThing() delivers only the changed content of the thing, that's on purpose in order to save bandwith.
When you want to receive the complete state of the thing with each consumed change, you can define extra fields via signal enrichment when starting the consumption of twin events in the client:

dittoClient.twin().startConsumption(
    Options.Consumption.extraFields(
        JsonFieldSelector.newInstance("thingId","policyId","attributes","features")
    )
)