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

        final ObjectNode result = context.mapper().createObjectNode();

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

        if (address.getIpv4() != null) {
            ObjectNode ipv4Node = addressCodec.encode(address.getIpv4(), context);
            result.set(IPV4, ipv4Node);
        }

        if (address.getIpv6() != null) {
            ObjectNode ipv6Node = addressCodec.encode(address.getIpv6(), context);
            result.set(IPV6, ipv6Node);
        }

        if (address.getIpv4() == null && address.getIpv6() == null) {
            log.error("Either IPv4 or IPv6 address should be specified.");
        }

        return result;
    }
@Test
    public void testLispListAddressEncode() {
        LispListAddress address = new LispListAddress.Builder()
                .withIpv4(MappingAddresses.ipv4MappingAddress(IPV4_PREFIX))
                .withIpv6(MappingAddresses.ipv6MappingAddress(IPV6_PREFIX))
                .build();
        ObjectNode addressJson = listAddressCodec.encode(address, context);
        assertThat("errors in encoding List address JSON",
                addressJson, LispListAddressJsonMatcher.matchesListAddress(address));
    }