@Override
    public ObjectNode encode(MappingTreatment treatment, CodecContext context) {
        checkNotNull(treatment, "Mapping treatment cannot be null");

        final ObjectNode result = context.mapper().createObjectNode();
        final ArrayNode jsonInstructions = result.putArray(INSTRUCTIONS);

        final JsonCodec<MappingInstruction> instructionCodec =
                context.codec(MappingInstruction.class);

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

        for (final MappingInstruction instruction : treatment.instructions()) {
            jsonInstructions.add(instructionCodec.encode(instruction, context));
        }

        result.set(ADDRESS, addressCodec.encode(treatment.address(), context));

        return result;
    }
@Test
    public void testMappingTreatmentEncode() {
        MappingInstruction unicastWeight = MappingInstructions.unicastWeight(UNICAST_WEIGHT);
        MappingInstruction unicastPriority = MappingInstructions.unicastPriority(UNICAST_PRIORITY);
        MappingInstruction multicastWeight = MappingInstructions.multicastWeight(MULTICAST_WEIGHT);
        MappingInstruction multicastPriority = MappingInstructions.multicastPriority(MULTICAST_PRIORITY);

        MappingAddress address = MappingAddresses.asMappingAddress(ASN_NUMBER);

        MappingTreatment treatment = DefaultMappingTreatment.builder()
                                                .add(unicastWeight)
                                                .add(unicastPriority)
                                                .add(multicastWeight)
                                                .add(multicastPriority)
                                                .withAddress(address)
                                                .build();

        ObjectNode treatmentJson = treatmentCodec.encode(treatment, context);
        assertThat(treatmentJson, MappingTreatmentJsonMatcher.matchesMappingTreatment(treatment));
    }