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

        final ObjectNode result = context.mapper().createObjectNode();
        final ArrayNode jsonTreatments = result.putArray(TREATMENTS);

        final JsonCodec<MappingTreatment> treatmentCodec =
                context.codec(MappingTreatment.class);

        final JsonCodec<MappingAction> actionCodec =
                context.codec(MappingAction.class);

        for (final MappingTreatment treatment : value.treatments()) {
            jsonTreatments.add(treatmentCodec.encode(treatment, context));
        }

        result.set(ACTION, actionCodec.encode(value.action(), context));

        return result;
    }
@Test
    public void testMappingValueEncode() {
        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.ipv4MappingAddress(IPV4_PREFIX);

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

        MappingAction action = MappingActions.noAction();

        MappingValue value = DefaultMappingValue.builder()
                                        .add(treatment)
                                        .withAction(action)
                                        .build();

        ObjectNode valueJson = valueCodec.encode(value, context);
        assertThat(valueJson, MappingValueJsonMatcher.matchesMappingValue(value));
    }