FasterXML / jackson-databind

General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)
Apache License 2.0
3.52k stars 1.38k forks source link

Add new tag-on interface, `ToStringConverter` for "Key Serializers" to implement #4276

Open cowtowncoder opened 9 months ago

cowtowncoder commented 9 months ago

In order to support cases of "stringified" serialization, we need to add a new interface; call it ToStringConverter, which can be implemented by one or both of:

  1. Value serializers
  2. Key serializers

The idea came from

https://github.com/FasterXML/jackson-datatypes-collections/issues/135

(or rather, its serialization counterpart)

where it is necessary to support "Stringified" serialization format for structured datatype.

Similar needs probably exists for other dataformats like CSV, and perhaps Properties.

Note: for deserialization, KeyDeserializer already works: but unfortunately we never added matching KeySerializer (intead, JsonSerializer is used, just has to write JsonToken.FIELD_NAME instead of JsonToken.VALUE_STRING.

cowtowncoder commented 9 months ago

NOTE: we do still have the question of whether to access such converters via regular "value" serializers or "key" serializers. Or, in theory, could just add new set of configuration.

But due to need to contextualize serializers, it may be better to tag these on to KeySerializers; meaning that lookup to obtain a converter is by finding a key serializer (of type JsonSerializer<?>) and see that it implements ToStringConverter (if not, cannot use).