@Override
    public ObjectNode encode(LispNatAddress address, CodecContext context) {
        checkNotNull(address, "LispListAddress cannot be null");

        final ObjectNode result = context.mapper().createObjectNode()
                .put(MS_UDP_PORT_NUMBER, address.getMsUdpPortNumber())
                .put(ETR_UDP_PORT_NUMBER, address.getEtrUdpPortNumber());

        final JsonCodec<MappingAddress> addressCodec =
                context.codec(MappingAddress.class);

        if (address.getGlobalEtrRlocAddress() != null) {
            ObjectNode globalEtrRlocNode =
                    addressCodec.encode(address.getGlobalEtrRlocAddress(), context);
            result.set(GLOBAL_ETR_RLOC_ADDRESS, globalEtrRlocNode);
        }

        if (address.getMsRlocAddress() != null) {
            ObjectNode msRlocNode =
                    addressCodec.encode(address.getMsRlocAddress(), context);
            result.set(MS_RLOC_ADDRESS, msRlocNode);
        }

        if (address.getPrivateEtrRlocAddress() != null) {
            ObjectNode privateEtrRlocNode =
                    addressCodec.encode(address.getPrivateEtrRlocAddress(), context);
            result.set(PRIVATE_ETR_RLOC_ADDRESS, privateEtrRlocNode);
        }

        final ArrayNode jsonRtrRlocNodes = result.putArray(RTR_RLOC_ADDRESSES);

        if (address.getRtrRlocAddresses() != null) {
            for (final MappingAddress mappingAddress : address.getRtrRlocAddresses()) {
                jsonRtrRlocNodes.add(addressCodec.encode(mappingAddress, context));
            }
        }

        return result;
    }
@Test
    public void testLispNatAddressEncode() {

        List<MappingAddress> rtrRlocs =
                ImmutableList.of(MappingAddresses.ipv4MappingAddress(GLOBAL_ETR_RLOC_ADDRESS),
                        MappingAddresses.ipv4MappingAddress(MS_RLOC_ADDRESS),
                        MappingAddresses.ipv4MappingAddress(PRIVATE_ETR_RLOC_ADDRESS));


        LispNatAddress address = new LispNatAddress.Builder()
                .withMsUdpPortNumber(MS_UDP_PORT_NUMBER)
                .withEtrUdpPortNumber(ETR_UDP_PORT_NUMBER)
                .withGlobalEtrRlocAddress(MappingAddresses.ipv4MappingAddress(GLOBAL_ETR_RLOC_ADDRESS))
                .withMsRlocAddress(MappingAddresses.ipv4MappingAddress(MS_RLOC_ADDRESS))
                .withPrivateEtrRlocAddress(MappingAddresses.ipv4MappingAddress(PRIVATE_ETR_RLOC_ADDRESS))
                .withRtrRlocAddresses(rtrRlocs)
                .build();

        ObjectNode addressJson = natAddressCodec.encode(address, context);
        assertThat("errors in encoding NAT address JSON",
                addressJson, LispNatAddressJsonMatcher.matchesNatAddress(address));
    }