@Test public void simple() throws Exception { File json = json(new String[] { "{}", }); ParameterTable table = ParameterTableHandler.parse(json); assertThat(table.getRowCount(), is(1)); List<ParameterSet> rows = table.getRows(); assertThat(rows.get(0).toMap(), is(map())); }
static ParameterTable parse(File file) throws IOException { LOG.debug("parsing JSON parameter table: {}", file); JsonFactory json = new JsonFactory(); json.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE); json.enable(JsonParser.Feature.ALLOW_COMMENTS); json.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES); json.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES); json.enable(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER); json.enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS); try (JsonParser parser = json.createParser(file)) { ParameterTable.Builder builder = IterativeExtensions.builder(); while (true) { JsonToken t = parser.nextToken(); if (t == null) { break; } else if (t == JsonToken.START_OBJECT) { builder.next(); parseRow(parser, builder); } else { throw new IOException(MessageFormat.format( "invalid JSON format (invalid start object): {0}", parser.getCurrentLocation())); } } return builder.build(); } }
ParameterTableHandler implements ExtensionHandler { static ParameterTable parse(File file) throws IOException { LOG.debug("parsing JSON parameter table: {}", file); JsonFactory json = new JsonFactory(); json.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE); json.enable(JsonParser.Feature.ALLOW_COMMENTS); json.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES); json.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES); json.enable(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER); json.enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS); try (JsonParser parser = json.createParser(file)) { ParameterTable.Builder builder = IterativeExtensions.builder(); while (true) { JsonToken t = parser.nextToken(); if (t == null) { break; } else if (t == JsonToken.START_OBJECT) { builder.next(); parseRow(parser, builder); } else { throw new IOException(MessageFormat.format( "invalid JSON format (invalid start object): {0}", parser.getCurrentLocation())); } } return builder.build(); } } }
ParameterTableHandler implements ExtensionHandler { static ParameterTable parse(File file) throws IOException { LOG.debug("parsing JSON parameter table: {}", file); JsonFactory json = new JsonFactory(); json.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE); json.enable(JsonParser.Feature.ALLOW_COMMENTS); json.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES); json.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES); json.enable(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER); json.enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS); try (JsonParser parser = json.createParser(file)) { ParameterTable.Builder builder = IterativeExtensions.builder(); while (true) { JsonToken t = parser.nextToken(); if (t == null) { break; } else if (t == JsonToken.START_OBJECT) { builder.next(); parseRow(parser, builder); } else { throw new IOException(MessageFormat.format( "invalid JSON format (invalid start object): {0}", parser.getCurrentLocation())); } } return builder.build(); } }  }
ParameterTableHandler implements ExtensionHandler { static ParameterTable parse(File file) throws IOException { LOG.debug("parsing JSON parameter table: {}", file); JsonFactory json = new JsonFactory(); json.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE); json.enable(JsonParser.Feature.ALLOW_COMMENTS); json.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES); json.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES); json.enable(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER); json.enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS); try (JsonParser parser = json.createParser(file)) { ParameterTable.Builder builder = IterativeExtensions.builder(); while (true) { JsonToken t = parser.nextToken(); if (t == null) { break; } else if (t == JsonToken.START_OBJECT) { builder.next(); parseRow(parser, builder); } else { throw new IOException(MessageFormat.format( "invalid JSON format (invalid start object): {0}", parser.getCurrentLocation())); } } return builder.build(); } }  @Override Extension handle(String tag, String value); }
ParameterTableHandler implements ExtensionHandler { static ParameterTable parse(File file) throws IOException { LOG.debug("parsing JSON parameter table: {}", file); JsonFactory json = new JsonFactory(); json.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE); json.enable(JsonParser.Feature.ALLOW_COMMENTS); json.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES); json.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES); json.enable(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER); json.enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS); try (JsonParser parser = json.createParser(file)) { ParameterTable.Builder builder = IterativeExtensions.builder(); while (true) { JsonToken t = parser.nextToken(); if (t == null) { break; } else if (t == JsonToken.START_OBJECT) { builder.next(); parseRow(parser, builder); } else { throw new IOException(MessageFormat.format( "invalid JSON format (invalid start object): {0}", parser.getCurrentLocation())); } } return builder.build(); } }  @Override Extension handle(String tag, String value); static final String TAG; }