All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.ext.consul.ServiceEntryListConverter Maven / Gradle / Ivy

The newest version!
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;

/**
 * Converter and mapper for {@link io.vertx.ext.consul.ServiceEntryList}.
 * NOTE: This class has been automatically generated from the {@link io.vertx.ext.consul.ServiceEntryList} original class using Vert.x codegen.
 */
public class ServiceEntryListConverter {

   static void fromJson(Iterable> json, ServiceEntryList obj) {
    for (java.util.Map.Entry 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 list =  new java.util.ArrayList<>();
            ((Iterable)member.getValue()).forEach( item -> {
              if (item instanceof JsonObject)
                list.add(new io.vertx.ext.consul.ServiceEntry((io.vertx.core.json.JsonObject)item));
            });
            obj.setList(list);
          }
          break;
      }
    }
  }

   static void toJson(ServiceEntryList obj, JsonObject json) {
    toJson(obj, json.getMap());
  }

   static void toJson(ServiceEntryList obj, java.util.Map json) {
    json.put("index", obj.getIndex());
    if (obj.getList() != null) {
      JsonArray array = new JsonArray();
      obj.getList().forEach(item -> array.add(item.toJson()));
      json.put("list", array);
    }
  }
}