JsonRecords { public static List<MultimapRecord> parseAsMultimap(File jsonFile) throws FileNotFoundException, IOException, JsonSyntaxException { return parseAsMultimap(jsonFile, new CountingDocIdGenerator()); }  static List<MapRecord> parseAsMap(File jsonFile); static List<MultimapRecord> parseAsMultimap(File jsonFile); static List<MapRecord> parseAsMap(File jsonFile, DocIdGenerator generator); static List<MultimapRecord> parseAsMultimap(File jsonFile, DocIdGenerator generator); static List<MapRecord> parseAsMap(String json); static List<MultimapRecord> parseAsMultimap(String json); static List<MapRecord> parseAsMap(String json, DocIdGenerator generator); static List<MultimapRecord> parseAsMultimap(String json, DocIdGenerator generator);  }
@Test(expected = JsonParseException.class) public void invalidJsonMultimap() { String json = "[{'foo1"; JsonRecords.parseAsMultimap(json); }
@Test(expected = JsonParseException.class) public void nonSupportedJsonMultimap() { String json = "{'foo1':'bar1'}"; JsonRecords.parseAsMultimap(json); }
@Test public void duplicateKeysInMultimap() { String json = "[ {'foo':1, 'foo':2} ]"; MultimapRecord record = JsonRecords.parseAsMultimap(json).get(0); Collection<RecordValue<?>> values = record.get(Column.create("foo")); Assert.assertEquals(1, values.size()); Assert.assertEquals(2, values.iterator().next().value()); }
@Test public void arrayValueInMultimap() { String json = "[ {'foo':[1, 2]} ]"; MultimapRecord record = JsonRecords.parseAsMultimap(json).get(0); Collection<RecordValue<?>> values = record.get(Column.create("foo")); Set<Integer> ints = Sets.newHashSet(); for (RecordValue<?> value : values) { ints.add(((IntegerRecordValue) value).value()); } Assert.assertEquals(ImmutableSet.of(1, 2), ints); }
@Test(expected = RuntimeException.class) public void nestedArrayInValue() { String json = "[ {'foo':[1, [2]]} ]"; JsonRecords.parseAsMultimap(json); }
@Test(expected = RuntimeException.class) public void objectInArrayInValue() { String json = "[ {'foo':[1, {'foo':2} ]} ]"; JsonRecords.parseAsMultimap(json); }