@Override
    public ObjectNode encode(KubevirtApiConfig entity, CodecContext context) {
        ObjectNode node = context.mapper().createObjectNode()
                .put(SCHEME, entity.scheme().name())
                .put(IP_ADDRESS, entity.ipAddress().toString())
                .put(PORT, entity.port())
                .put(STATE, entity.state().name())
                .put(DATACENTER_ID, entity.datacenterId())
                .put(CLUSTER_ID, entity.clusterId());

        if (entity.scheme() == HTTPS) {
            node.put(CA_CERT_DATA, entity.caCertData())
                    .put(CLIENT_CERT_DATA, entity.clientCertData())
                    .put(CLIENT_KEY_DATA, entity.clientKeyData());

            if (entity.token() != null) {
                node.put(TOKEN, entity.token());
            }

        } else {
            if (entity.token() != null) {
                node.put(TOKEN, entity.token());
            }

            if (entity.caCertData() != null) {
                node.put(CA_CERT_DATA, entity.caCertData());
            }

            if (entity.clientCertData() != null) {
                node.put(CLIENT_CERT_DATA, entity.clientCertData());
            }

            if (entity.clientKeyData() != null) {
                node.put(CLIENT_KEY_DATA, entity.clientKeyData());
            }
        }

        if (entity.serviceFqdn() != null) {
            node.put(SERVICE_FQDN, entity.serviceFqdn());
        }

        if (entity.apiServerFqdn() != null) {
            node.put(API_SERVER_FQDN, entity.apiServerFqdn());
        }

        if (entity.controllerIp() != null) {
            node.put(CONTROLLER_IP, entity.controllerIp().toString());
        }

        return node;
    }
@Test
    public void testKubevirtApiConfigEncode() {
        KubevirtApiConfig config = DefaultKubevirtApiConfig.builder()
                .scheme(HTTPS)
                .ipAddress(IpAddress.valueOf("10.10.10.23"))
                .port(6443)
                .state(CONNECTED)
                .token("token")
                .caCertData("caCertData")
                .clientCertData("clientCertData")
                .clientKeyData("clientKeyData")
                .serviceFqdn("kubevirt.edgestack.svc.cluster.local")
                .apiServerFqdn("kubernetes.default.svc.cluster.local")
                .controllerIp(IpAddress.valueOf("127.0.0.1"))
                .datacenterId("BD")
                .clusterId("BD-MEH-CT01")
                .build();

        ObjectNode configJson = kubevirtApiConfigCodec.encode(config, context);
        assertThat(configJson, matchesKubevirtApiConfig(config));
    }