use of com.serotonin.json.JsonReader in project ma-core-public by infiniteautomation.
the class PopulateTest method test1.
static void test1() throws JsonException, IOException {
List<BaseClass> list = new ArrayList<BaseClass>();
list.add(new Subclass1());
list.add(new Subclass2());
String json = JsonWriter.writeToString(context, list);
System.out.println(json);
JsonReader reader = new JsonReader(context, json);
TypeDefinition type = new TypeDefinition(List.class, BaseClass.class);
list.clear();
reader.readInto(type, list);
System.out.println(list);
}
use of com.serotonin.json.JsonReader in project ma-core-public by infiniteautomation.
the class ReadTest method read.
static void read(String data, Object obj, Type type) throws Exception {
JsonReader reader = new JsonReader(context, data);
while (!reader.isDone()) {
reader.readInto(type, obj);
System.out.println(obj);
}
}
use of com.serotonin.json.JsonReader in project ma-core-public by infiniteautomation.
the class EventDetectorRowMapper method mapRow.
/* (non-Javadoc)
* @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
*/
@Override
public AbstractEventDetectorVO<?> mapRow(ResultSet rs, int rowNum) throws SQLException {
EventDetectorDefinition<?> definition = ModuleRegistry.getEventDetectorDefinition(rs.getString(this.firstColumn + 3));
if (definition == null)
throw new ShouldNeverHappenException("Event Detector defintion of type: " + rs.getString(this.firstColumn + 3) + " not found.");
AbstractEventDetectorVO<?> vo = definition.baseCreateEventDetectorVO();
vo.setId(rs.getInt(this.firstColumn));
vo.setXid(rs.getString(this.firstColumn + 1));
vo.setDefinition(definition);
// Extract the source id
int sourceIdColumnIndex;
if (this.sourceIdColumnOffset < 0)
sourceIdColumnIndex = this.firstColumn + 5 + EventDetectorDao.instance.getSourceIdIndex(definition.getSourceTypeName());
else
sourceIdColumnIndex = this.firstColumn + this.sourceIdColumnOffset;
vo.setSourceId(rs.getInt(sourceIdColumnIndex));
// Read Into Detector
JsonTypeReader typeReader = new JsonTypeReader(rs.getString(this.firstColumn + 4));
try {
JsonValue value = typeReader.read();
JsonObject root = value.toJsonObject();
JsonReader reader = new JsonReader(Common.JSON_CONTEXT, root);
root.remove("handlers");
reader.readInto(vo);
} catch (ClassCastException | IOException | JsonException e) {
LOG.error(e.getMessage(), e);
}
return vo;
}
Aggregations