@Test public void testFromJson() throws Exception { LocalQuery lq = new LocalQuery(); lq.requireContentFieldEquals("x", 1); lq.requireContentFieldExists("x"); lq.requireContentFieldNotExists("y"); lq.requireTouchedByStage("s"); lq.requireNotTouchedByStage("s2"); lq.requireAction(Action.DELETE); LocalQuery lq2 = new LocalQuery(lq.toJson()); if(!lq2.getContentsEquals().get("x").equals(1)) { fail("Equals was lost in serialization"); } if(!lq2.getContentsExists().get("x")) { fail("Exists 'true' was lost in serialization"); } if(lq2.getContentsExists().get("y")) { fail("Exists 'false' was lost in serialization"); } if(!lq2.getTouched().get("s")) { fail("Touched 'true' was lost in serialization"); } if(lq2.getTouched().get("s2")) { fail("Touched 'false' was lost in serialization"); } if(lq2.getAction()!=Action.DELETE) { fail("Action was lost in serialization"); } }
@SuppressWarnings({ "unchecked" }) @Override public void fromJson(String json) throws JsonException{ try { Map<String, Object> queryObject = (Map<String, Object>) SerializationUtils.fromJson(json); if(queryObject.containsKey("equals")) { equals = (Map<String, Object>) queryObject.get("equals"); } if(queryObject.containsKey("notEquals")) { notEquals = (Map<String, Object>) queryObject.get("notEquals"); } if(queryObject.containsKey("exists")) { exists = (Map<String, Boolean>) queryObject.get("exists"); } if(queryObject.containsKey("touched")) { touched = (Map<String, Boolean>) queryObject.get("touched"); } if(queryObject.containsKey("action")) { action = Action.valueOf((String)queryObject.get("action")); } } catch(JsonParseException jse) { throw new JsonException(jse); } }
LocalQuery implements Query, JsonDeserializer { @SuppressWarnings({ "unchecked" }) @Override public void fromJson(String json) throws JsonException{ try { Map<String, Object> queryObject = (Map<String, Object>) SerializationUtils.fromJson(json); if(queryObject.containsKey("equals")) { equals = (Map<String, Object>) queryObject.get("equals"); } if(queryObject.containsKey("notEquals")) { notEquals = (Map<String, Object>) queryObject.get("notEquals"); } if(queryObject.containsKey("exists")) { exists = (Map<String, Boolean>) queryObject.get("exists"); } if(queryObject.containsKey("touched")) { touched = (Map<String, Boolean>) queryObject.get("touched"); } if(queryObject.containsKey("action")) { action = Action.valueOf((String)queryObject.get("action")); } } catch(JsonParseException jse) { throw new JsonException(jse); } } }
LocalQuery implements Query, JsonDeserializer { @SuppressWarnings({ "unchecked" }) @Override public void fromJson(String json) throws JsonException{ try { Map<String, Object> queryObject = (Map<String, Object>) SerializationUtils.fromJson(json); if(queryObject.containsKey("equals")) { equals = (Map<String, Object>) queryObject.get("equals"); } if(queryObject.containsKey("notEquals")) { notEquals = (Map<String, Object>) queryObject.get("notEquals"); } if(queryObject.containsKey("exists")) { exists = (Map<String, Boolean>) queryObject.get("exists"); } if(queryObject.containsKey("touched")) { touched = (Map<String, Boolean>) queryObject.get("touched"); } if(queryObject.containsKey("action")) { action = Action.valueOf((String)queryObject.get("action")); } } catch(JsonParseException jse) { throw new JsonException(jse); } } LocalQuery();  LocalQuery(String json); }
LocalQuery implements Query, JsonDeserializer { @SuppressWarnings({ "unchecked" }) @Override public void fromJson(String json) throws JsonException{ try { Map<String, Object> queryObject = (Map<String, Object>) SerializationUtils.fromJson(json); if(queryObject.containsKey("equals")) { equals = (Map<String, Object>) queryObject.get("equals"); } if(queryObject.containsKey("notEquals")) { notEquals = (Map<String, Object>) queryObject.get("notEquals"); } if(queryObject.containsKey("exists")) { exists = (Map<String, Boolean>) queryObject.get("exists"); } if(queryObject.containsKey("touched")) { touched = (Map<String, Boolean>) queryObject.get("touched"); } if(queryObject.containsKey("action")) { action = Action.valueOf((String)queryObject.get("action")); } } catch(JsonParseException jse) { throw new JsonException(jse); } } LocalQuery();  LocalQuery(String json); Map<String, Boolean> getContentsExists(); Map<String, Boolean> getTouched(); Map<String, Object> getContentsEquals(); Map<String, Object> getEquals(); Map<String, Object> getContentNotEquals(); Map<String, Object> getNotEquals(); Map<String, Boolean> getExists(); Action getAction(); @Override void requireContentFieldExists(String fieldName); @Override void requireContentFieldNotExists(String fieldName); @Override void requireContentFieldEquals(String fieldName, Object o); @Override void requireContentFieldNotEquals(String fieldName, Object o); @Override void requireTouchedByStage(String stageName); @Override void requireNotTouchedByStage(String stageName); @Override void requireAction(Action action); String toJson(); @SuppressWarnings({ "unchecked" }) @Override void fromJson(String json); @Override String toString(); }
LocalQuery implements Query, JsonDeserializer { @SuppressWarnings({ "unchecked" }) @Override public void fromJson(String json) throws JsonException{ try { Map<String, Object> queryObject = (Map<String, Object>) SerializationUtils.fromJson(json); if(queryObject.containsKey("equals")) { equals = (Map<String, Object>) queryObject.get("equals"); } if(queryObject.containsKey("notEquals")) { notEquals = (Map<String, Object>) queryObject.get("notEquals"); } if(queryObject.containsKey("exists")) { exists = (Map<String, Boolean>) queryObject.get("exists"); } if(queryObject.containsKey("touched")) { touched = (Map<String, Boolean>) queryObject.get("touched"); } if(queryObject.containsKey("action")) { action = Action.valueOf((String)queryObject.get("action")); } } catch(JsonParseException jse) { throw new JsonException(jse); } } LocalQuery();  LocalQuery(String json); Map<String, Boolean> getContentsExists(); Map<String, Boolean> getTouched(); Map<String, Object> getContentsEquals(); Map<String, Object> getEquals(); Map<String, Object> getContentNotEquals(); Map<String, Object> getNotEquals(); Map<String, Boolean> getExists(); Action getAction(); @Override void requireContentFieldExists(String fieldName); @Override void requireContentFieldNotExists(String fieldName); @Override void requireContentFieldEquals(String fieldName, Object o); @Override void requireContentFieldNotEquals(String fieldName, Object o); @Override void requireTouchedByStage(String stageName); @Override void requireNotTouchedByStage(String stageName); @Override void requireAction(Action action); String toJson(); @SuppressWarnings({ "unchecked" }) @Override void fromJson(String json); @Override String toString();  }