/** * Parses a rule from the given column. Used by the Tree class when scanning a row for rules. * * @param column The column to parse * @return A valid TreeRule object if parsed successfully * @throws IllegalArgumentException if the column was empty * @throws JSONException if the object could not be serialized */ public static TreeRule parseFromStorage(final KeyValue column) { if (column.value() == null) { throw new IllegalArgumentException("Tree rule column value was null"); } final TreeRule rule = JSON.parseToObject(column.value(), TreeRule.class); rule.initializeChangedMap(); return rule; }
@Test public void deserialize() throws Exception { String json = "{\"tsuid\":\"ABCD\",\"" + "description\":\"Description\",\"notes\":\"Notes\",\"created\":1328140800," + "\"custom\":null,\"units\":\"\",\"retention\":42,\"max\":1.0,\"min\":" + "\"NaN\",\"displayName\":\"Display\",\"dataType\":\"Data\",\"lastReceived" + "\":1328140801,\"unknownkey\":null}"; TSMeta tsmeta = JSON.parseToObject(json, TSMeta.class); assertNotNull(tsmeta); assertEquals("ABCD", tsmeta.getTSUID()); assertEquals("Notes", tsmeta.getNotes()); assertEquals(42, tsmeta.getRetention()); }