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

io.knotx.fragments.action.library.http.options.EndpointOptionsConverter Maven / Gradle / Ivy

package io.knotx.fragments.action.library.http.options;

import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import java.time.Instant;
import java.time.format.DateTimeFormatter;

/**
 * Converter for {@link io.knotx.fragments.action.library.http.options.EndpointOptions}.
 * NOTE: This class has been automatically generated from the {@link io.knotx.fragments.action.library.http.options.EndpointOptions} original class using Vert.x codegen.
 */
 class EndpointOptionsConverter {

   static void fromJson(Iterable> json, EndpointOptions obj) {
    for (java.util.Map.Entry member : json) {
      switch (member.getKey()) {
        case "additionalHeaders":
          if (member.getValue() instanceof JsonObject) {
            obj.setAdditionalHeaders(((JsonObject)member.getValue()).copy());
          }
          break;
        case "allowedRequestHeaders":
          if (member.getValue() instanceof JsonArray) {
            java.util.LinkedHashSet list =  new java.util.LinkedHashSet<>();
            ((Iterable)member.getValue()).forEach( item -> {
              if (item instanceof String)
                list.add((String)item);
            });
            obj.setAllowedRequestHeaders(list);
          }
          break;
        case "body":
          if (member.getValue() instanceof String) {
            obj.setBody((String)member.getValue());
          }
          break;
        case "bodyJson":
          if (member.getValue() instanceof JsonObject) {
            obj.setBodyJson(((JsonObject)member.getValue()).copy());
          }
          break;
        case "domain":
          if (member.getValue() instanceof String) {
            obj.setDomain((String)member.getValue());
          }
          break;
        case "interpolateBody":
          if (member.getValue() instanceof Boolean) {
            obj.setInterpolateBody((Boolean)member.getValue());
          }
          break;
        case "interpolatePath":
          if (member.getValue() instanceof Boolean) {
            obj.setInterpolatePath((Boolean)member.getValue());
          }
          break;
        case "path":
          if (member.getValue() instanceof String) {
            obj.setPath((String)member.getValue());
          }
          break;
        case "port":
          if (member.getValue() instanceof Number) {
            obj.setPort(((Number)member.getValue()).intValue());
          }
          break;
      }
    }
  }

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

   static void toJson(EndpointOptions obj, java.util.Map json) {
    if (obj.getAdditionalHeaders() != null) {
      json.put("additionalHeaders", obj.getAdditionalHeaders());
    }
    if (obj.getAllowedRequestHeaders() != null) {
      JsonArray array = new JsonArray();
      obj.getAllowedRequestHeaders().forEach(item -> array.add(item));
      json.put("allowedRequestHeaders", array);
    }
    if (obj.getBody() != null) {
      json.put("body", obj.getBody());
    }
    if (obj.getBodyJson() != null) {
      json.put("bodyJson", obj.getBodyJson());
    }
    if (obj.getDomain() != null) {
      json.put("domain", obj.getDomain());
    }
    json.put("interpolateBody", obj.isInterpolateBody());
    json.put("interpolatePath", obj.isInterpolatePath());
    if (obj.getPath() != null) {
      json.put("path", obj.getPath());
    }
    json.put("port", obj.getPort());
  }
}