@Override
    public ObjectNode encode(KubevirtNetwork network, CodecContext context) {
        checkNotNull(network, "Kubevirt network cannot be null");

        ObjectNode result = context.mapper().createObjectNode()
                .put(NETWORK_ID, network.networkId())
                .put(TYPE, network.type().name())
                .put(NAME, network.name())
                .put(MTU, network.mtu())
                .put(GATEWAY_IP, network.gatewayIp().toString())
                .put(DEFAULT_ROUTE, network.defaultRoute())
                .put(CIDR, network.cidr());

        if (network.segmentId() != null) {
            result.put(SEGMENT_ID, network.segmentId());
        }

        if (network.hostRoutes() != null && !network.hostRoutes().isEmpty()) {
            ArrayNode hostRoutes = context.mapper().createArrayNode();
            network.hostRoutes().forEach(hostRoute -> {
                ObjectNode hostRouteJson =
                        context.codec(KubevirtHostRoute.class).encode(hostRoute, context);
                hostRoutes.add(hostRouteJson);
            });
            result.set(HOST_ROUTES, hostRoutes);
        }

        if (network.ipPool() != null) {
            ObjectNode ipPoolJson = context.codec(KubevirtIpPool.class).encode(network.ipPool(), context);
            result.set(IP_POOL, ipPoolJson);
        }

        if (network.dnses() != null && !network.dnses().isEmpty()) {
            ArrayNode dnses = context.mapper().createArrayNode();
            network.dnses().forEach(dns -> {
                dnses.add(dns.toString());
            });
            result.set(DNSES, dnses);
        }

        return result;
    }
@Test
    public void testKubevirtNetworkEncode() {
        KubevirtHostRoute hostRoute1 = new KubevirtHostRoute(IpPrefix.valueOf("10.10.10.0/24"),
                IpAddress.valueOf("20.20.20.1"));
        KubevirtHostRoute hostRoute2 = new KubevirtHostRoute(IpPrefix.valueOf("20.20.20.0/24"),
                IpAddress.valueOf("10.10.10.1"));

        KubevirtIpPool ipPool = new KubevirtIpPool(IpAddress.valueOf("10.10.10.100"),
                IpAddress.valueOf("10.10.10.200"));

        KubevirtNetwork network = DefaultKubevirtNetwork.builder()
                .networkId("net-1")
                .name("net-1")
                .type(KubevirtNetwork.Type.FLAT)
                .gatewayIp(IpAddress.valueOf("10.10.10.1"))
                .defaultRoute(true)
                .mtu(1500)
                .cidr("10.10.10.0/24")
                .hostRoutes(ImmutableSet.of(hostRoute1, hostRoute2))
                .ipPool(ipPool)
                .dnses(ImmutableSet.of(IpAddress.valueOf("8.8.8.8")))
                .build();

        ObjectNode networkJson = kubevirtNetworkCodec.encode(network, context);
        assertThat(networkJson, matchesKubevirtNetwork(network));
    }