Spring Custom Object Mapper for non-standard JSON
<p>I'm using Spring's RestTemplate, to hit a restful webservice and getting non-standard JSON back.</p>

<p>Here is what I mean:</p>

<pre><code>{
    ...
    rules : {
        matched : "rule one",
        matched : "rule B",
        matched : "another rule"
    }
    ...
}
</code></pre>

<p>So basically I need this Hash mapped to a list. In my pojo I would like the field to look like this:</p>

<pre><code>private List&lt;String&gt; rules; // once parsed, should contain "rule one",
                    // "rule B", "another rule", etc
</code></pre>

<p>Here is what I have attempted thus far.
Here's my serializer:</p>

<pre><code>import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

public class MapValuesToListSerializer extends JsonSerializer&lt;Map&lt;?, ?&gt;&gt; {

    @Override
    public void serialize(Map&lt;?, ?&gt; map, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        serializerProvider.defaultSerializeValue(map.values(), jsonGenerator);
    }
}
</code></pre>

<p>And within my POJO, I've annotated my field like this:</p>

<pre><code>@JsonSerialize(using = MapValuesToListSerializer.class)
private List&lt;String&gt; rules;
</code></pre>

<p>This doesn't work. The standard fields all serialize correctly, but not the non-standard fields that conform to this field. I'm missing an important piece to this, but I do not know what.</p>