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

io.vertx.core.http.WebSocketConnectOptionsConverter Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR1
Show newest version
package io.vertx.core.http;

import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.impl.JsonUtil;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Base64;

/**
 * Converter and mapper for {@link io.vertx.core.http.WebSocketConnectOptions}.
 * NOTE: This class has been automatically generated from the {@link io.vertx.core.http.WebSocketConnectOptions} original class using Vert.x codegen.
 */
public class WebSocketConnectOptionsConverter {


  private static final Base64.Decoder BASE64_DECODER = JsonUtil.BASE64_DECODER;
  private static final Base64.Encoder BASE64_ENCODER = JsonUtil.BASE64_ENCODER;

   static void fromJson(Iterable> json, WebSocketConnectOptions obj) {
    for (java.util.Map.Entry member : json) {
      switch (member.getKey()) {
        case "allowOriginHeader":
          if (member.getValue() instanceof Boolean) {
            obj.setAllowOriginHeader((Boolean)member.getValue());
          }
          break;
        case "registerWriteHandlers":
          if (member.getValue() instanceof Boolean) {
            obj.setRegisterWriteHandlers((Boolean)member.getValue());
          }
          break;
        case "subProtocols":
          if (member.getValue() instanceof JsonArray) {
            java.util.ArrayList list =  new java.util.ArrayList<>();
            ((Iterable)member.getValue()).forEach( item -> {
              if (item instanceof String)
                list.add((String)item);
            });
            obj.setSubProtocols(list);
          }
          break;
        case "version":
          if (member.getValue() instanceof String) {
            obj.setVersion(io.vertx.core.http.WebsocketVersion.valueOf((String)member.getValue()));
          }
          break;
      }
    }
  }

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

   static void toJson(WebSocketConnectOptions obj, java.util.Map json) {
    json.put("allowOriginHeader", obj.getAllowOriginHeader());
    json.put("registerWriteHandlers", obj.isRegisterWriteHandlers());
    if (obj.getSubProtocols() != null) {
      JsonArray array = new JsonArray();
      obj.getSubProtocols().forEach(item -> array.add(item));
      json.put("subProtocols", array);
    }
    if (obj.getVersion() != null) {
      json.put("version", obj.getVersion().name());
    }
  }
}