I have created a simple test case that shows the error. Please let me know if I've missed something.
I have a simple interface that declares a single accessor:
public class JacksonParsingTest {
public interface EventWithMap {
Map<String, String> getContextMap();
}
@Test
public void testJsonMapDeserializes()
throws JsonParseException, JsonMappingException, IOException
{
String json = "{\"contextMap\":[" +
"{\"key\":\"processedAt\",\"value\":\"Thu Dec 31 14:30:51 EST 2015\"}" +
"]}";
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule( new MrBeanModule() );
EventWithMap e = mapper.readValue( json, EventWithMap.class );
assertEquals( "Thu Dec 31 14:30:51 EST 2015", e.getContextMap().get( "processedAt" ) );
}
}
When I run this unit test, Jackson fails on parsing the json string:
com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.LinkedHashMap out of START_ARRAY token
at [Source: {"contextMap":[{"key":"processedAt","value":"Thu Dec 31 14:30:51 EST 2015"}]}; line: 1, column: 2] (through reference chain: RecoveryEventBuilderTest$EventWithMap["contextMap"])
As you can see from the stacktrace, Jackson correctly extracts the contextMap token from the json but it fails to continue tokenizing the string. As far as I know, the json string correctly represents a map.
Thanks, Robin.