/** * Convenience for using transitory data as a flag. Removes the transitory data for this key if one existed. * * @param key the key for the transitory data * @return true if a transitory object is set for the given flag, false otherwise */ public boolean checkAndClearTransitory(String key) { if (hasTransitory(key)) { clearTransitory(key); return true; } return false; }
/** * Deserialize a JSON string property into the specified Java type */ public static <T> T getValueFromJSON(AbstractModel model, JSONProperty<T> property, Type javaType) { String transitoryKey = transitoryKeyForProperty(property); checkCacheIntegrity(model, property, transitoryKey); if (!model.hasTransitory(transitoryKey)) { T data = null; String json = model.get(property); // Will throw if model doesn't have property if (json != null) { try { if (MAPPER == null) { throw new NullPointerException("JSONPropertySupport needs to be initialized with a " + "JSONMapper instance using setJSONMapper()"); } data = MAPPER.fromJSON(json, javaType); } catch (Exception e) { // TODO: Should this throw or at least not cache null? Logger.w(TAG, "Error deserializing JSON string: " + json, e); model.clearValue(property); } } putJSONTransitory(model, transitoryKey, data, json); return data; } JSONObjectHolder<T> holder = getJSONTransitory(model, transitoryKey); return holder.parsedObject; }
private static void checkCacheIntegrity(AbstractModel model, JSONProperty<?> property, String transitoryKey) { if (!model.hasTransitory(transitoryKey)) { return; } JSONObjectHolder<?> holder = getJSONTransitory(model, transitoryKey); if (model.containsValue(property) || model.getDefaultValues().containsKey(property.getName())) { String jsonValue = model.get(property); if (SqlUtils.equals(holder.jsonString, jsonValue)) { return; } } model.clearTransitory(transitoryKey); }
/** * Convenience for using transitory data as a flag. Removes the transitory data for this key if one existed. * * @param key the key for the transitory data * @return true if a transitory object is set for the given flag, false otherwise */ public boolean checkAndClearTransitory(String key) { if (hasTransitory(key)) { clearTransitory(key); return true; } return false; }