@Test public void testListKeyChains() { List<Object[]> keyChains = JoltUtils.listKeyChains(jsonSource); for(int i=0; i<keyChains.size(); i++) { Object[] keyChain = keyChains.get(i); Object expected = flattenedValues[i]; Object actual = navigate(jsonSource, keyChain); Assert.assertEquals(actual, expected); } keyChains = JoltUtils.listKeyChains(jsonSource_empty); for(Object[] keyChain: keyChains) { Assert.assertTrue(isVacantJson(navigate(jsonSource_empty, keyChain))); } }
public static List<Object[]> listKeyChains(final Object source) { List<Object[]> keyChainList = new LinkedList<>(); if(source instanceof Map) { Map sourceMap = (Map) source; for (Object key: sourceMap.keySet()) { keyChainList.addAll(listKeyChains(key, sourceMap.get(key))); } } else if(source instanceof List) { List sourceList = (List) source; for(int i=0; i<sourceList.size(); i++) { keyChainList.addAll(listKeyChains(i, sourceList.get(i))); } } else { return Collections.emptyList(); } return keyChainList; }
JoltUtils { public static List<Object[]> listKeyChains(final Object source) { List<Object[]> keyChainList = new LinkedList<>(); if(source instanceof Map) { Map sourceMap = (Map) source; for (Object key: sourceMap.keySet()) { keyChainList.addAll(listKeyChains(key, sourceMap.get(key))); } } else if(source instanceof List) { List sourceList = (List) source; for(int i=0; i<sourceList.size(); i++) { keyChainList.addAll(listKeyChains(i, sourceList.get(i))); } } else { return Collections.emptyList(); } return keyChainList; } }
JoltUtils { public static List<Object[]> listKeyChains(final Object source) { List<Object[]> keyChainList = new LinkedList<>(); if(source instanceof Map) { Map sourceMap = (Map) source; for (Object key: sourceMap.keySet()) { keyChainList.addAll(listKeyChains(key, sourceMap.get(key))); } } else if(source instanceof List) { List sourceList = (List) source; for(int i=0; i<sourceList.size(); i++) { keyChainList.addAll(listKeyChains(i, sourceList.get(i))); } } else { return Collections.emptyList(); } return keyChainList; }  }
JoltUtils { public static List<Object[]> listKeyChains(final Object source) { List<Object[]> keyChainList = new LinkedList<>(); if(source instanceof Map) { Map sourceMap = (Map) source; for (Object key: sourceMap.keySet()) { keyChainList.addAll(listKeyChains(key, sourceMap.get(key))); } } else if(source instanceof List) { List sourceList = (List) source; for(int i=0; i<sourceList.size(); i++) { keyChainList.addAll(listKeyChains(i, sourceList.get(i))); } } else { return Collections.emptyList(); } return keyChainList; }  static void removeRecursive( Object json, String keyToRemove ); static T navigate( final Object source, final Object... paths ); static T navigateStrict( final Object source, final Object... paths ); static T navigateOrDefault( final T defaultValue, final Object source, final Object... paths ); @Deprecated static T navigateSafe(final T defaultValue, final Object source, final Object... paths); static boolean isVacantJson(final Object obj); static boolean isBlankJson(final Object obj); static List<Object[]> listKeyChains(final Object source); static List<Object[]> listKeyChains(final Object key, final Object value); static String toSimpleTraversrPath(Object[] paths); @SuppressWarnings("unchecked") static T cast(Object object); @SuppressWarnings("unchecked") static E[] cast(Object[] object); @SuppressWarnings("unchecked") static Object compactJson(Object source); @SuppressWarnings( "unchecked" ) static T store( Object source, T value, Object... paths ); @SuppressWarnings( "unchecked" ) static T remove( Object source, Object... paths ); }
JoltUtils { public static List<Object[]> listKeyChains(final Object source) { List<Object[]> keyChainList = new LinkedList<>(); if(source instanceof Map) { Map sourceMap = (Map) source; for (Object key: sourceMap.keySet()) { keyChainList.addAll(listKeyChains(key, sourceMap.get(key))); } } else if(source instanceof List) { List sourceList = (List) source; for(int i=0; i<sourceList.size(); i++) { keyChainList.addAll(listKeyChains(i, sourceList.get(i))); } } else { return Collections.emptyList(); } return keyChainList; }  static void removeRecursive( Object json, String keyToRemove ); static T navigate( final Object source, final Object... paths ); static T navigateStrict( final Object source, final Object... paths ); static T navigateOrDefault( final T defaultValue, final Object source, final Object... paths ); @Deprecated static T navigateSafe(final T defaultValue, final Object source, final Object... paths); static boolean isVacantJson(final Object obj); static boolean isBlankJson(final Object obj); static List<Object[]> listKeyChains(final Object source); static List<Object[]> listKeyChains(final Object key, final Object value); static String toSimpleTraversrPath(Object[] paths); @SuppressWarnings("unchecked") static T cast(Object object); @SuppressWarnings("unchecked") static E[] cast(Object[] object); @SuppressWarnings("unchecked") static Object compactJson(Object source); @SuppressWarnings( "unchecked" ) static T store( Object source, T value, Object... paths ); @SuppressWarnings( "unchecked" ) static T remove( Object source, Object... paths );  }