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

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

        if (address.getAddress() != null) {
            final JsonCodec<MappingAddress> addressCodec =
                    context.codec(MappingAddress.class);
            ObjectNode addressNode = addressCodec.encode(address.getAddress(), context);
            result.set(ADDRESS, addressNode);
        }

        return result;
    }
@Test
    public void testLispSegmentAddressEncode() {
        LispSegmentAddress address = new LispSegmentAddress.Builder()
                .withInstanceId(INSTANCE_ID)
                .withAddress(MappingAddresses.ipv4MappingAddress(IPV4_PREFIX))
                .build();
        ObjectNode addressJson = segmentAddressCodec.encode(address, context);
        assertThat("errors in encoding segment address JSON",
                addressJson, LispSegmentAddressJsonMatcher.matchesSegmentAddress(address));
    }