JsonResource extends ResourceFilter { static List<KeyPiece> splitKeyPieces(String key) { if (USE_JSONPATH_PATTERN.matcher(key).matches()) { List<KeyPiece> result = new ArrayList<KeyPiece>(); boolean inQuotes = false; StringBuilder currentToken = new StringBuilder(); StringCharacterIterator i = new StringCharacterIterator(key.substring(JSONPATH_ROOT.length())); boolean inSubscript = false; while (i.current() != StringCharacterIterator.DONE) { char c = i.current(); if (c == '\'') { inQuotes = !inQuotes; } if (!inQuotes && (c == '.' || c == '[' || c == ']')) { if (currentToken.length() > 0) { addToken(result, currentToken.toString(), inSubscript); currentToken.setLength(0); if (inSubscript) { inSubscript = false; } } if (c == '[') { inSubscript = true; } } else { currentToken.append(c); } i.next(); } addToken(result, currentToken.toString(), inSubscript); return Collections.unmodifiableList(result); } return Collections.singletonList(new KeyPiece(key, JsonToken.BEGIN_OBJECT)); }  @Override LanguageBundle parse(InputStream inStream, FilterOptions options); @Override void write(OutputStream outStream, LanguageBundle languageBundle,
            FilterOptions options);  }
@Test public void testSplitKeyPieces() throws FileNotFoundException, IOException { JsonObject SPLITKEY_DATA = ResourceTestUtil.parseJson(SPLITKEYS).getAsJsonObject(); for (final Entry<String, JsonElement> e : SPLITKEY_DATA.entrySet()) { final String key = e.getKey(); final JsonArray expectList = e.getValue().getAsJsonArray(); List<KeyPiece> actualList = JsonResource.splitKeyPieces(key); String prefix = "‘" + key + "’: "; assertEquals(prefix + "key count", expectList.size(), actualList.size()); for (int n = 0; n < expectList.size(); n++) { JsonObject expectObject = expectList.get(n).getAsJsonObject(); KeyPiece actualObject = actualList.get(n); String subPrefix = prefix + " key " + n; assertEquals(subPrefix + " value ", expectObject.get("keyValue").getAsString(), actualObject.keyValue); assertEquals(subPrefix + " type ", expectObject.get("keyType").getAsString(), actualObject.keyType.name()); } } }