On Mon, Aug 5, 2019 at 4:22 PM Mark Derricutt <[email protected]> wrote:
>
> 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?

So, from Jackson perspective, handling of POJOs differs a lot from
serializing Maps, and only POJOs have fields/properties in that sense.
All standard rename options apply to POJOs, none for Maps, as well
(although some ignoral settings do work for Maps as well, including
`@JsonIgnoreProperties`). This is mostly because renaming options are
based on static mapping between external (expected) JSON names, and
internal POJO field names; nothing is calculated dynamically based on
content.

So that's one thing. Other part is that custom serializers and
deserializers registered for value types are not used for Map keys:
you can register custom key (de)serializers, but they are separate. In
your case, then, I think it's just matter of registering key
serializers along with value serializers.

-+ Tatu +-

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/CAL4a10hMTxFiHNWf-Y%2BZW-WhHah_uQn6G28wkxxjrcB%3D%2Bdf8yA%40mail.gmail.com.

Reply via email to