package io.vertx.ext.consul;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
public class ServiceOptionsConverter {
public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, ServiceOptions obj) {
for (java.util.Map.Entry<String, Object> member : json) {
switch (member.getKey()) {
case "address":
if (member.getValue() instanceof String) {
obj.setAddress((String)member.getValue());
}
break;
case "checkOptions":
if (member.getValue() instanceof JsonObject) {
obj.setCheckOptions(new io.vertx.ext.consul.CheckOptions((JsonObject)member.getValue()));
}
break;
case "id":
if (member.getValue() instanceof String) {
obj.setId((String)member.getValue());
}
break;
case "meta":
if (member.getValue() instanceof JsonObject) {
java.util.Map<String, java.lang.String> map = new java.util.LinkedHashMap<>();
((Iterable<java.util.Map.Entry<String, Object>>)member.getValue()).forEach(entry -> {
if (entry.getValue() instanceof String)
map.put(entry.getKey(), (String)entry.getValue());
});
obj.setMeta(map);
}
break;
case "name":
if (member.getValue() instanceof String) {
obj.setName((String)member.getValue());
}
break;
case "port":
if (member.getValue() instanceof Number) {
obj.setPort(((Number)member.getValue()).intValue());
}
break;
case "tags":
if (member.getValue() instanceof JsonArray) {
java.util.ArrayList<java.lang.String> list = new java.util.ArrayList<>();
((Iterable<Object>)member.getValue()).forEach( item -> {
if (item instanceof String)
list.add((String)item);
});
obj.setTags(list);
}
break;
}
}
}
public static void toJson(ServiceOptions obj, JsonObject json) {
toJson(obj, json.getMap());
}
public static void toJson(ServiceOptions obj, java.util.Map<String, Object> json) {
if (obj.getAddress() != null) {
json.put("address", obj.getAddress());
}
if (obj.getCheckOptions() != null) {
json.put("checkOptions", obj.getCheckOptions().toJson());
}
if (obj.getId() != null) {
json.put("id", obj.getId());
}
if (obj.getMeta() != null) {
JsonObject map = new JsonObject();
obj.getMeta().forEach((key, value) -> map.put(key, value));
json.put("meta", map);
}
if (obj.getName() != null) {
json.put("name", obj.getName());
}
json.put("port", obj.getPort());
if (obj.getTags() != null) {
JsonArray array = new JsonArray();
obj.getTags().forEach(item -> array.add(item));
json.put("tags", array);
}
}
}