How to use jackson key serializers in a map of maps
<p>I am trying to serialize a java object structure to JSON with Jackson 2.5 and I am running into the following issue with key serializers:</p>

<pre><code>class MainContainer {
    private final Map&lt;String, Object&gt; entries;
}

class Item {
    // a lot of attributes
}

class ItemMapKeySerializer extends JsonSerializer&lt;Item&gt; {
     // serialize an item into something simple for map keys
}

class IntermediateContainer {
     private final Map&lt;Item, ... &gt; someMapping;
}
</code></pre>

<p>I register ItemMapKeySerializer as a SimpleModule in the ObjectMapper. When I add ItermediateContainer to MainContainer, the ItemMapKeySerializer is used. When I add a Map with Item as keys directly into MainContainer, ItemMapKeySerializer is not used and I am not sure why.</p>

<p>This code:</p>

<pre><code>MainContainer.add("test", new IntermediateContainer(Map.of(new Item(), ...)));
</code></pre>

<p>Leads to this JSON:</p>

<pre><code> entries: {
    "test": {
        someMapping: {
            "my nice item 1": {
            ...
            }             
        }
    }
}
</code></pre>

<p>Whereas this code:</p>

<pre><code>MainContainer.add("test", Map.of(new Item(), ...));
</code></pre>

<p>Leads to this JSON:</p>

<pre><code> entries: {
    "test": {
        Item@12D23: {  // This kind of fieldname is not desired
        ...
        }             
    }
}
</code></pre>

<p>So when I use a Map as a value in a Map, the key serializer does is not used, but that is what I would like to happen. Does anyone have an idea how to accomplish this?</p>

<p>Thanks,
Benni</p>