エラーを示す簡単なテスト ケースを作成しました。何か見逃した場合はお知らせください。
単一のアクセサーを宣言する単純なインターフェイスがあります。
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" ) );
}
}
この単体テストを実行すると、Jackson は json 文字列の解析に失敗します。
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"])
スタックトレースからわかるように、Jackson は json から contextMap トークンを正しく抽出しますが、文字列のトークン化を続行できません。私の知る限り、json 文字列はマップを正しく表しています。
ありがとう、ロビン。