GlobalizeJsResource extends JsonResource { @Override public LanguageBundle parse(InputStream inStream, FilterOptions options) throws IOException, ResourceFilterException { LanguageBundleBuilder bb = new LanguageBundleBuilder(false); try (InputStreamReader reader = new InputStreamReader(new BomInputStream(inStream), StandardCharsets.UTF_8)) { JsonElement root = new JsonParser().parse(reader); if (!root.isJsonObject()) { throw new IllegalResourceFormatException("The root JSON element is not a JSON object."); } JsonObject root_obj = root.getAsJsonObject(); Set<Map.Entry<String, JsonElement>> root_elements = root_obj.entrySet(); if (root_elements.size() != 1) { throw new IllegalResourceFormatException( "Only one top level language tag element is allowed per file."); } Map.Entry<String, JsonElement> top_level = root_elements.iterator().next(); String language = top_level.getKey(); bb.embeddedLanguageCode(language); JsonElement language_obj = top_level.getValue(); if (!language_obj.isJsonObject()) { throw new IllegalResourceFormatException("The top level language element is not a JSON object."); } addBundleStrings(language_obj.getAsJsonObject(), "", bb, 0); } catch (JsonParseException e) { throw new IllegalResourceFormatException("Failed to parse the specified JSON contents.", e); } return bb.build(); }  @Override LanguageBundle parse(InputStream inStream, FilterOptions options);  }
@Test public void testParse() throws IOException, ResourceFilterException { assertTrue("The input test file <" + INPUT_FILE + "> does not exist.", INPUT_FILE.exists()); try (InputStream is = new FileInputStream(INPUT_FILE)) { LanguageBundle bundle = res.parse(is, null); List<ResourceString> resStrList = new ArrayList<>(bundle.getResourceStrings()); Collections.sort(resStrList, new ResourceStringComparator()); assertEquals("ResourceStrings did not match.", EXPECTED_INPUT_RES_LIST, resStrList); } }