@Override
    public ObjectNode encode(KubevirtLoadBalancer lb, CodecContext context) {
        checkNotNull(lb, "Kubevirt load balancer cannot be null");

        ObjectNode result = context.mapper().createObjectNode()
                .put(NAME, lb.name())
                .put(VIP, lb.vip().toString())
                .put(NETWORK_ID, lb.networkId());

        if (lb.description() != null) {
            result.put(DESCRIPTION, lb.description());
        }

        if (lb.members() != null && !lb.members().isEmpty()) {
            ArrayNode members = context.mapper().createArrayNode();
            for (IpAddress ip : lb.members()) {
                members.add(ip.toString());
            }
            result.set(MEMBERS, members);
        }

        if (lb.rules() != null && !lb.rules().isEmpty()) {
            ArrayNode rules = context.mapper().createArrayNode();
            for (KubevirtLoadBalancerRule rule : lb.rules()) {
                ObjectNode ruleJson = context.codec(
                        KubevirtLoadBalancerRule.class).encode(rule, context);
                rules.add(ruleJson);
            }
            result.set(RULES, rules);
        }

        return result;
    }
@Test
    public void testKubevirtLoadBalancerEncode() {
        KubevirtLoadBalancer lb = DefaultKubevirtLoadBalancer.builder()
                .name("lb-1")
                .networkId("net-1")
                .vip(IpAddress.valueOf("10.10.10.10"))
                .members(ImmutableSet.of(IpAddress.valueOf("10.10.10.11"),
                        IpAddress.valueOf("10.10.10.12")))
                .rules(ImmutableSet.of(RULE1, RULE2, RULE3))
                .description("network load balancer")
                .build();

        ObjectNode lbJson = kubevirtLoadBalancerCodec.encode(lb, context);
        assertThat(lbJson, matchesKubevirtLoadBalancer(lb));
    }