public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, KeyValueList obj) { for (java.util.Map.Entry<String, Object> member : json) { switch (member.getKey()) { case "index": if (member.getValue() instanceof Number) { obj.setIndex(((Number)member.getValue()).longValue()); } break; case "list": if (member.getValue() instanceof JsonArray) { java.util.ArrayList<io.vertx.ext.consul.KeyValue> list = new java.util.ArrayList<>(); ((Iterable<Object>)member.getValue()).forEach( item -> { if (item instanceof JsonObject) list.add(new io.vertx.ext.consul.KeyValue((JsonObject)item)); }); obj.setList(list); } break; } } }
static KeyValue parse(JsonObject json) { return new KeyValue() .setKey(json.getString(KEY_KEY)) .setValue(Utils.decode64(json.getString(VALUE_KEY))) .setSession(json.getString(SESSION_KEY)) .setFlags(json.getLong(FLAGS_KEY, 0L)) .setCreateIndex(json.getLong(CREATE_KEY, 0L)) .setModifyIndex(json.getLong(MODIFY_KEY, 0L)) .setLockIndex(json.getLong(LOCK_KEY, 0L)); } }
@Override public ConsulClient getValueWithOptions(String key, BlockingQueryOptions options, Handler<AsyncResult<KeyValue>> resultHandler) { request(KV_VALID_CODES, HttpMethod.GET, "/v1/kv/" + urlEncode(key), new Query().put(options), null, resultHandler, resp -> { if (resp.statusCode() == HttpResponseStatus.NOT_FOUND.code()) { return new KeyValue(); } else { return KVParser.parse(resp.bodyAsJsonArray().getJsonObject(0)); } }); return this; }
/** * Constructor from JSON * * @param json the JSON */ public TxnResponse(JsonObject json) { if (json.getValue("Results") instanceof JsonArray) { json.getJsonArray("Results").forEach(entry -> { JsonObject obj = (JsonObject) entry; if (obj.containsKey("KV")) { results.add(new KeyValue(obj.getJsonObject("KV"))); } }); } if (json.getValue("Errors") instanceof JsonArray) { json.getJsonArray("Errors").forEach(entry -> errors.add(new TxnError((JsonObject) entry))); } }
public static KeyValue randomKeyValue() { return new KeyValue() .setKey(randomAlphaString(10)) .setValue(randomAlphaString(10)) .setSession(randomAlphaString(10)) .setCreateIndex(randomLong()) .setFlags(randomLong()) .setModifyIndex(randomLong()) .setLockIndex(randomLong()); }