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

        ObjectNode result = context.mapper().createObjectNode()
                .put(VM_NAME, port.vmName())
                .put(NETWORK_ID, port.networkId())
                .put(MAC_ADDRESS, port.macAddress().toString());

        if (port.ipAddress() != null) {
            result.put(IP_ADDRESS, port.ipAddress().toString());
        }

        if (port.deviceId() != null) {
            result.put(DEVICE_ID, port.deviceId().toString());
        }

        if (port.portNumber() != null) {
            result.put(PORT_NUMBER, port.portNumber().toString());
        }

        if (port.securityGroups() != null) {
            ArrayNode sgIds = context.mapper().createArrayNode();
            for (String sgId : port.securityGroups()) {
                sgIds.add(sgId);
            }
            result.set(SECURITY_GROUPS, sgIds);
        }

        return result;
    }
@Test
    public void testKubevirtPortEncode() {
        KubevirtPort port = DefaultKubevirtPort.builder()
                .vmName("test-vm-1")
                .networkId("net-1")
                .macAddress(MacAddress.valueOf("11:22:33:44:55:66"))
                .ipAddress(IpAddress.valueOf("10.10.10.100"))
                .deviceId(DeviceId.deviceId("of:foo"))
                .portNumber(PortNumber.portNumber("1"))
                .build();
        ObjectNode portJson = kubevirtPortCodec.encode(port, context);
        assertThat(portJson, matchesKubevirtPort(port));
    }