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

        final ObjectNode result = context.mapper().createObjectNode()
                .put(INSTANCE_ID, address.getInstanceId())
                .put(SRC_MASK_LENGTH, address.getSrcMaskLength())
                .put(GRP_MASK_LENGTH, address.getGrpMaskLength());

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

        if (address.getSrcAddress() != null) {
            ObjectNode srcAddressNode = addressCodec.encode(address.getSrcAddress(), context);
            result.set(SRC_ADDRESS, srcAddressNode);
        }

        if (address.getGrpAddress() != null) {
            ObjectNode grpAddressNode = addressCodec.encode(address.getGrpAddress(), context);
            result.set(GRP_ADDRESS, grpAddressNode);
        }

        return result;
    }
@Test
    public void testLispMulticastAddressEncode() {
        LispMulticastAddress address = new LispMulticastAddress.Builder()
                .withInstanceId(INSTANCE_ID)
                .withSrcMaskLength(SRC_MASK_LENGTH)
                .withGrpMaskLength(GRP_MASK_LENGTH)
                .withSrcAddress(MappingAddresses.ipv4MappingAddress(SRC_ADDRESS_PREFIX))
                .withGrpAddress(MappingAddresses.ipv4MappingAddress(GRP_ADDRESS_PREFIX))
                .build();
        ObjectNode addressJson = multicastAddressCodec.encode(address, context);
        assertThat("errors in encoding Multicast address JSON",
                addressJson, LispMulticastAddressJsonMatcher.matchesMulticastAddress(address));
    }