Twin Class
- java.
lang. Object - com.
microsoft. azure. sdk. iot. device. twin. Twin
- com.
public class Twin
Representation of a single Twin.
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
</code> in the rest API. <pre><code>{
"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
}
}
}
}
</code></pre></p>
Constructor Summary
Constructor
Description
Twin(TwinCollection desiredProperty, TwinCollection reportedProperty)
CONSTRUCTOR
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
}
}
}
}
Method Summary
Modifier and Type
Method and Description
Twin
createFromDesiredPropertyJson(String json)
Factory
Create a new instance of the Twin parsing the provided string as a JSON with only desired properties information.
Twin
createFromPropertiesJson(String json)
Factory
Create a new instance of the Twin parsing the provided string as a JSON with only desired properties information.
Twin
createFromReportedPropertyJson(String json)
Factory
Create a new instance of the Twin parsing the provided string as a JSON with only reported properties information.
Twin
createFromTwinJson(String json)
Factory
Create a new instance of the Twin parsing the provided string as a JSON with the full Twin information.
TwinCollection
getDesiredProperties()
Getter for the desired property.
TwinCollection
getReportedProperties()
Getter for the reported property.
JsonElement
toJsonElement()
Serializer
Creates aJsonElement
</code> , which the content represents the information in this class and its subclasses in a JSON format.</p>
This is useful if the caller will integrate this JSON with JSON from other classes to generate a consolidated JSON.
String
toString()
Creates a pretty print JSON with the content of this class and subclasses.
Constructor Details
Twin
public Twin(TwinCollection desiredProperty, TwinCollection reportedProperty)
CONSTRUCTOR
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
}
}
}
}
Parameters:
Method Details
createFromDesiredPropertyJson
public static Twin createFromDesiredPropertyJson(String json)
Factory
Create a new instance of the Twin parsing the provided string as a JSON with only desired properties information.
Parameters:
json
- theString
</code> with the JSON received from the service. It cannot be<code>null
</code> or empty. </p>
Returns:
The new instance of theTwin
</code> . </p>
createFromPropertiesJson
public static Twin createFromPropertiesJson(String json)
Factory
Create a new instance of the Twin parsing the provided string as a JSON with only desired properties information.
Parameters:
json
- theString
</code> with the JSON received from the service. It cannot be<code>null
</code> or empty. </p>
Returns:
The new instance of theTwin
</code> . </p>
createFromReportedPropertyJson
public static Twin createFromReportedPropertyJson(String json)
Factory
Create a new instance of the Twin parsing the provided string as a JSON with only reported properties information.
Parameters:
json
- theString
</code> with the JSON received from the service. It cannot be<code>null
</code> or empty. </p>
Returns:
The new instance of theTwin
</code> . </p>
createFromTwinJson
public static Twin createFromTwinJson(String json)
Factory
Create a new instance of the Twin parsing the provided string as a JSON with the full Twin information.
Parameters:
json
- theString
</code> with the JSON received from the service. It cannot be<code>null
</code> or empty. </p>
Returns:
The new instance of theTwin
</code> . </p>
getDesiredProperties
public TwinCollection getDesiredProperties()
Getter for the desired property.
Returns:
TheTwinCollection
</code> with the desired property content. It can be<code>null
</code> . </p>
getReportedProperties
public TwinCollection getReportedProperties()
Getter for the reported property.
Returns:
TheTwinCollection
</code> with the reported property content. It can be<code>null
</code> . </p>
toJsonElement
public JsonElement toJsonElement()
Serializer
Creates aJsonElement
</code> , which the content represents the information in this class and its subclasses in a JSON format.</p>
This is useful if the caller will integrate this JSON with JSON from other classes to generate a consolidated JSON.
Returns:
TheJsonElement
</code> with the content of this class. </p>
toString
public String toString()
Creates a pretty print JSON with the content of this class and subclasses.
Returns:
TheString
</code> with the pretty print JSON. </p>
Applies to
Azure SDK for Java