Ok, that is quite an elaborate setup.
So... typically I recommend multi-phase processing for most structural
changes: first "serialize" content into `JsonNode` using
`ObjectMapper.valueToTree()`; then transform tree, and finally
serialize the modified tree as JSON.
This is especially true for cases where you need to apply
transformations for all kinds of types, not just specific classes.
Serializer/deserializer setup is designed more for strict(er) typing,
and as such is not necessarily good at applying things for all types.
But it is certainly possible to do this via serializers too. Usually I
would have looked at `StdDelegatingSerializer`, in which you can take
a specific type (that Jackson does not know how to properly
serialize), and construct alternative value (like `JsonNode` or `Map`)
and let Jackson serialize that instead. This is somewhat similar to
use of `@JsonValue` annotation, in which POJO is serialized using sort
of surrogate.
But I am not sure this approach would work here, since this is applied
to any types it seems (`Object`), and since you may want to operate on
outputs of standard Bean-style serialization.
As to use of `BeanSerializerFactory`: you are correct in suspecting
this is not the way to do it. It is not. :-)
Instead you would ideally do one of:
1. If types are statically known, implement `ContextualSerializer`, in
which you can get access to the "standard" serializer, keep reference
to it, add your own implementation that may call original one
(including giving it `TokenBuffer` as `JsonGenerator`!).
2. If types not known until actual serialization (dynamically) --
which I think is what you have here -- find serializer(s) via
`SerializerProvider`. It will call factory, as well as possible
extension modules, to find and initialize serializer.
I can help with (2) if you have hard time finding method to call; for
now I assume you can find it ok.
I hope this helps,
-+ Tatu +-