Hey all,
I have an internal SimpleModule which provides a custom serialiser for some types we use which works great when they're used as values, but not so much when they're keys in a map.
We're serialising out some internal Clojure data structures and keywords toString() as :test, and our custom module corrects that to just test, however, it seems when we have a map with say :count -> 5, I'm still seeing :count being serialised.
Am I correct in that a StdSerializer only works on the value side of things?
I see in DefaultSerializerProvider#_serialize:
private final void _serialize(JsonGenerator gen, Object value, JsonSerializer<Object> ser, PropertyName rootName) throws IOException {
try {
gen.writeStartObject();
gen.writeFieldName(rootName.simpleAsEncoded(this._config));
ser.serialize(value, gen, this);
which doesn't seem to serialise the field name at all, is what I want actually possible at all?
Cheers
Mark
"The ease with which a change can be implemented has no relevance at all to whether it is the right change for the (Java) Platform for all time." — Mark Reinhold.
Mark Derricutt
http://www.theoryinpractice.net
http://www.chaliceofblood.net
http://plus.google.com/+MarkDerricutt
http://twitter.com/talios
http://facebook.com/mderricutt
On 7 Aug 2019, at 7:52, Tatu Saloranta wrote:
In
your case, then, I think it's just matter of registering key
serializers along with value serializers.
That works a treat! Cheers - saves me recursing thru the data structure manually remapping keys to strings :)
On 7 Aug 2019, at 11:06, Tatu Saloranta wrote:
But at least once you know how things work support is just little bit more work.
Yep - was just adding a boolean flag to my construction to call writeFieldName vs writeString.
Was nice that it was a fairly trivial fix as well.