use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.
the class VarNames method jsonWriteVarContext.
public static void jsonWriteVarContext(ObjectWriter writer, List<IntStringPair> context) throws IOException, JsonException {
DataPointDao dataPointDao = DataPointDao.instance;
JsonArray pointList = new JsonArray();
for (IntStringPair p : context) {
JsonObject point = new JsonObject();
pointList.add(point);
point.put("varName", new JsonString(p.getValue()));
point.put("dataPointXid", new JsonString(dataPointDao.getXidById(p.getKey())));
}
writer.writeEntry("context", pointList);
}
use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.
the class VarNames method jsonReadVarContext.
public static void jsonReadVarContext(JsonObject json, List<IntStringPair> context) throws JsonException {
JsonArray jsonContext = json.getJsonArray("context");
if (jsonContext != null) {
context.clear();
DataPointDao dataPointDao = DataPointDao.instance;
for (JsonValue jv : jsonContext) {
JsonObject jo = jv.toJsonObject();
String xid = jo.getString("dataPointXid");
if (xid == null)
throw new TranslatableJsonException("emport.error.meta.missing", "dataPointXid");
Integer dpid = dataPointDao.getIdByXid(xid);
if (dpid == null)
throw new TranslatableJsonException("emport.error.missingPoint", xid);
String var = jo.getString("varName");
if (var == null)
throw new TranslatableJsonException("emport.error.meta.missing", "varName");
context.add(new IntStringPair(dpid, var));
}
}
}
use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.
the class JsonObjectConverter method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonValue jsonValue, Object obj, Type type) throws JsonException {
JsonObject jsonObject = (JsonObject) obj;
jsonObject.clear();
jsonObject.putAll(jsonValue.toJsonObject());
}
use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.
the class JsonPropertyConverter method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonValue jsonValue, Object obj, Type type) throws JsonException {
JsonObject jsonObject = (JsonObject) jsonValue;
if (jsonSerializable)
((JsonSerializable) obj).jsonRead(reader, jsonObject);
if (properties != null) {
for (SerializableProperty prop : properties) {
// Check whether the property should be included
if (!prop.include(reader.getIncludeHint()))
continue;
Method writeMethod = prop.getWriteMethod();
if (writeMethod == null)
continue;
String name = prop.getNameToUse();
JsonValue propJsonValue = jsonObject.get(name);
if (propJsonValue == null)
continue;
Type propType = writeMethod.getGenericParameterTypes()[0];
propType = TypeUtils.resolveTypeVariable(type, propType);
Class<?> propClass = TypeUtils.getRawClass(propType);
try {
Object propValue = reader.read(propType, propJsonValue);
if (propClass.isPrimitive() && propValue == null) {
if (propClass == Boolean.TYPE)
propValue = false;
else
propValue = 0;
}
prop.getWriteMethod().invoke(obj, propValue);
} catch (Exception e) {
throw new JsonException("JsonException writing property '" + prop.getName() + "' of class " + propClass.getName(), e);
}
}
}
}
use of com.serotonin.json.type.JsonObject in project ma-core-public by infiniteautomation.
the class JsonEmportScriptUtility method doExclusions.
private void doExclusions(JsonObject jo) {
for (JsonImportExclusion exclusion : importExclusions) {
if (jo.containsKey(exclusion.getImporterType())) {
JsonArray ja = jo.getJsonArray(exclusion.getImporterType());
int size = ja.size();
for (int k = 0; k < size; k += 1) {
JsonObject obj = ja.getJsonObject(k);
if (obj.containsKey(exclusion.getKey()) && obj.getString(exclusion.getKey()).equals(exclusion.getValue())) {
ja.remove(k);
k -= 1;
size -= 1;
}
}
}
}
}
Aggregations