Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

AttributeState convenience method for JsonValue conversion

Rich Turner28c6c457ee4b
diff --git a/model/src/main/java/org/openremote/model/AttributeState.java b/model/src/main/java/org/openremote/model/AttributeState.java
index 92c8b2728..3adb694d1 100644
--- a/model/src/main/java/org/openremote/model/AttributeState.java
+++ b/model/src/main/java/org/openremote/model/AttributeState.java
@@ -20,6 +20,8 @@
package org.openremote.model;
import elemental.json.Json;
+import elemental.json.JsonArray;
+import elemental.json.JsonObject;
import elemental.json.JsonValue;
/**
@@ -33,6 +35,11 @@ public class AttributeState {
protected AttributeState() {
}
+ public AttributeState(JsonObject jsonObject) {
+ attributeRef = new AttributeRef(jsonObject.get("attributeRef"));
+ value = jsonObject.get("value");
+ }
+
public AttributeState(AttributeRef attributeRef, JsonValue value) {
this.attributeRef = attributeRef;
this.value = value == null ? Json.createNull() : value;
@@ -46,6 +53,13 @@ public class AttributeState {
return value;
}
+ public JsonValue asJsonValue() {
+ JsonObject jsonObject = Json.createObject();
+ jsonObject.put("attributeRef", attributeRef != null ? attributeRef.asJsonValue() : Json.createNull());
+ jsonObject.put("value", value != null ? value : Json.createNull());
+ return jsonObject;
+ }
+
@Override
public String toString() {
return getClass().getSimpleName() + "{" +