FasterXML / jackson-datatypes-misc

Collection of common Jackson datatype modules not part of other multi-project repos
Apache License 2.0
22 stars 20 forks source link

Add delegating serializers for `JsonPatch` and `JsonMergePatch` #28

Closed mattnelson closed 1 year ago

mattnelson commented 1 year ago

To simplify the serialization of json-p patch objects, proposing adding delegating serializers for JsonPatch>JsonArray and JsonMergePatch>JsonValue

It takes extra steps to convert a patch into a type that has a serializer available.

        addSerializer(JsonPatch.class, new StdDelegatingSerializer(new Converter<JsonPatch, JsonArray>() {
            @Override
            public JsonArray convert(JsonPatch value) {
                return value.toJsonArray();
            }
            @Override
            public JavaType getInputType(TypeFactory typeFactory) {
                return typeFactory.constructFromCanonical(JsonPatch.class.getName());
            }
            @Override
            public JavaType getOutputType(TypeFactory typeFactory) {
                return typeFactory.constructFromCanonical(JsonArray.class.getName());
            }
        }));
cowtowncoder commented 1 year ago

Sounds good to me. Since this does not require changes to API, could even go in 2.14(.2) patch.

cowtowncoder commented 1 year ago

Implemented as suggested; will be included in 2.14.2