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

        ObjectNode result =  context.mapper().createObjectNode()
                .put(NETWORK_ID, port.networkId())
                .put(PORT_ID, port.portId())
                .put(MAC_ADDRESS, port.macAddress().toString())
                .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.state() != null) {
            result.put(STATE, port.state().name());
        }

        return result;
    }
@Test
    public void testK8sPortEncode() {
        K8sPort port = DefaultK8sPort.builder()
                .networkId("network-1")
                .portId("port-1")
                .deviceId(DeviceId.deviceId("of:0000000000000001"))
                .ipAddress(IpAddress.valueOf("10.10.10.2"))
                .macAddress(MacAddress.valueOf("00:11:22:33:44:55"))
                .portNumber(PortNumber.portNumber(1))
                .state(ACTIVE)
                .build();

        ObjectNode nodeJson = k8sPortCodec.encode(port, context);
        assertThat(nodeJson, matchesK8sPort(port));
    }