FacebookからのサンプルJSONデータ
{
"1111111" : {
"home" : false,
"activities" : "some value"
},
"2222222" : {
"home" : false,
"activities" : "some value again"
}
}
public class Profile{
private boolean home;
private String activities;
// generated setter getter
public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
Profile mainProfile = mapper.readValue(new File("data.json"), Profile.class);
System.out.println(mainProfile.getActivities().size());
}
}
上記のファイルを実行すると、このエラーが発生します。
Unrecognized field "1111111" (Class com.analysis.structure.Profile), not marked as ignorable
私が直面している問題は、その「1111111」値をクラス内の変数にマップする方法です。@JsonIgnoreProperties(ignoreUnknown = true)を使用すると、最初のデータにマップするタグがないため、すべてのjosnデータが完全に無視されます。Jackson JSONを使用してこのタイプのjsonデータをJavaにマッピングするにはどうすればよいですか?