public class Twin
extends java.lang.Object
The Twin can contain one TwinCollection
of Tags, and one
TwinCollection
of properties.desired.
Each entity in the collections can contain a associated TwinMetadata
.
These metadata are provided by the Service and contains information about the last updated date time, and version.
For instance, the following is a valid Twin, represented as
initialTwin
in the rest API.
{
"initialTwin": {
"tags":{
"SpeedUnity":"MPH",
"$metadata":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":4,
"SpeedUnity":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":4
}
},
"$version":4
},
"properties":{
"desired": {
"MaxSpeed":{
"Value":500,
"NewValue":300
},
"$metadata":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":4,
"MaxSpeed":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":4,
"Value":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":4
},
"NewValue":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":4
}
}
},
"$version":4
},
"reported": {
"MaxSpeed":{
"Value":500,
"NewValue":300
},
"$metadata":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":5,
"MaxSpeed":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":4,
"Value":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":5
},
"NewValue":{
"$lastUpdated":"2017-09-21T02:07:44.238Z",
"$lastUpdatedVersion":4
}
}
},
"$version":6
}
}
}
}
Constructor and Description |
---|
Twin(TwinCollection desiredProperty,
TwinCollection reportedProperty)
CONSTRUCTOR
|
Modifier and Type | Method and Description |
---|---|
static Twin |
createFromDesiredPropertyJson(java.lang.String json)
Factory
|
static Twin |
createFromPropertiesJson(java.lang.String json)
Factory
|
static Twin |
createFromReportedPropertyJson(java.lang.String json)
Factory
|
static Twin |
createFromTwinJson(java.lang.String json)
Factory
|
TwinCollection |
getDesiredProperties()
Getter for the desired property.
|
TwinCollection |
getReportedProperties()
Getter for the reported property.
|
com.google.gson.JsonElement |
toJsonElement()
Serializer
|
java.lang.String |
toString()
Creates a pretty print JSON with the content of this class and subclasses.
|
public Twin(TwinCollection desiredProperty, TwinCollection reportedProperty)
This constructor creates an instance of the Twin with the provided TwinCollection
tags and desired properties.
When serialized, this class will looks like the following example:
"initialTwin": {
"tags":{
"SpeedUnity":"MPH",
"$version":4
}
"properties":{
"desired":{
"MaxSpeed":{
"Value":500,
"NewValue":300
},
"$version":4
}
}
}
}
desiredProperty
- the TwinCollection
with the desired properties. It can be null
.reportedProperty
- the TwinCollection
with the reported properties. It can be null
.public com.google.gson.JsonElement toJsonElement()
Creates a JsonElement
, which the content represents
the information in this class and its subclasses 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.public TwinCollection getDesiredProperties()
TwinCollection
with the desired property content. It can be null
.public TwinCollection getReportedProperties()
TwinCollection
with the reported property content. It can be null
.public java.lang.String toString()
toString
in class java.lang.Object
String
with the pretty print JSON.public static Twin createFromTwinJson(java.lang.String json)
Create a new instance of the Twin parsing the provided string as a JSON with the full Twin information.
json
- the String
with the JSON received from the service. It cannot be null
or empty.Twin
.public static Twin createFromDesiredPropertyJson(java.lang.String json)
Create a new instance of the Twin parsing the provided string as a JSON with only desired properties information.
json
- the String
with the JSON received from the service. It cannot be null
or empty.Twin
.public static Twin createFromReportedPropertyJson(java.lang.String json)
Create a new instance of the Twin parsing the provided string as a JSON with only reported properties information.
json
- the String
with the JSON received from the service. It cannot be null
or empty.Twin
.public static Twin createFromPropertiesJson(java.lang.String json)
Create a new instance of the Twin parsing the provided string as a JSON with only desired properties information.
json
- the String
with the JSON received from the service. It cannot be null
or empty.Twin
.Copyright © 2023. All rights reserved.