public class TwinMetadata extends Object
TwinCollection.
The metadata is a set of pairs lastUpdated/lastUpdatedVersion for each property and sub-property in the Twin. It is optionally provided by the service and the clients can only ready it.
This class store the Date and Version for each entity in the TwinCollection.
For instance, the following is a valid TwinCollection with its metadata.
"$metadata":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":4,
"MaxSpeed":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":3,
"Value":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":5
},
"NewValue":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":5
}
}
}
| Modifier and Type | Field and Description |
|---|---|
static String |
LAST_UPDATE_TAG |
static String |
LAST_UPDATE_VERSION_TAG |
| Modifier and Type | Method and Description |
|---|---|
Date |
getLastUpdated()
Getter for the lastUpdated.
|
Integer |
getLastUpdatedVersion()
Getter for the lastUpdatedVersion.
|
protected com.google.gson.JsonElement |
toJsonElement()
Serializer
|
String |
toString()
Creates a pretty print JSON with the content of this class and subclasses.
|
protected static TwinMetadata |
tryExtractFromMap(Object metadata)
Metadata extractor
|
public static final String LAST_UPDATE_TAG
public static final String LAST_UPDATE_VERSION_TAG
protected static TwinMetadata tryExtractFromMap(Object metadata)
This internal method will try to find $lastUpdated and $lastUpdatedVersion at the first level of the provided Map (Object), and create a new instance of the TwinMetadata with this information.
Once the provide Object can or cannot be a Map, and, if it is a Map, it can or cannot
contains a valid metadata, this method contains the label try, which means that
it can return a valid TwinMetadata or null.
For instance, for the follow Map, this method will create a TwinMetadata with
lastUpdated = 2015-09-21T02:07:44.238Z and lastUpdatedVersion = 3
"$lastUpdated":"2015-09-21T02:07:44.238Z",
"$lastUpdatedVersion":3,
"Value":{
"$lastUpdated":"2016-09-21T02:07:44.238Z",
"$lastUpdatedVersion":5
},
"NewValue":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":5
}
metadata - the Object that may contains the metadata.Object is a Map with
data and version metadata, or null for the other cases.IllegalArgumentException - If no valid parameter was provide and the class will be empty, or if the DateTime is invalid.public Integer getLastUpdatedVersion()
Integer with the stored lastUpdatedVersion. It can be null.public Date getLastUpdated()
Date with the stored lastUpdated. It can be null.protected com.google.gson.JsonElement toJsonElement()
Creates a JsonElement, which the content represents
the information in this class in a JSON format.
This is useful if the caller will integrate this JSON with JSON from
other classes to generate a consolidated JSON.
JsonElement with the content of this class.Copyright © 2019. All rights reserved.