@@ -569,6 +569,11 @@ public Chain<Map<String, Object>> set(final String path, Object value) {
569569 return new Chain <>(map ());
570570 }
571571
572+ public Chain <Map <String , Object >> set (final List <String > paths , Object value ) {
573+ U .set (map (), paths , value );
574+ return new Chain <>(map ());
575+ }
576+
572577 @ Override
573578 public Chain <T > reverse () {
574579 return new Chain <>(Underscore .reverse (value ()));
@@ -1715,10 +1720,9 @@ private enum OperationType {
17151720 @ SuppressWarnings ("unchecked" )
17161721 private static <T > T baseGetOrSetOrRemove (
17171722 final Map <String , Object > object ,
1718- final String path ,
1723+ final List < String > paths ,
17191724 final Object value ,
17201725 OperationType operationType ) {
1721- final List <String > paths = stringToPath (path );
17221726 int index = 0 ;
17231727 final int length = paths .size ();
17241728
@@ -1774,15 +1778,28 @@ private static Map.Entry getMapEntry(Map map) {
17741778 }
17751779
17761780 public static <T > T get (final Map <String , Object > object , final String path ) {
1777- return baseGetOrSetOrRemove (object , path , null , OperationType .GET );
1781+ return get (object , stringToPath (path ));
1782+ }
1783+
1784+ public static <T > T get (final Map <String , Object > object , final List <String > paths ) {
1785+ return baseGetOrSetOrRemove (object , paths , null , OperationType .GET );
17781786 }
17791787
17801788 public static <T > T set (final Map <String , Object > object , final String path , Object value ) {
1781- return baseGetOrSetOrRemove (object , path , value , OperationType .SET );
1789+ return set (object , stringToPath (path ), value );
1790+ }
1791+
1792+ public static <T > T set (
1793+ final Map <String , Object > object , final List <String > paths , Object value ) {
1794+ return baseGetOrSetOrRemove (object , paths , value , OperationType .SET );
17821795 }
17831796
17841797 public static <T > T remove (final Map <String , Object > object , final String path ) {
1785- return baseGetOrSetOrRemove (object , path , null , OperationType .REMOVE );
1798+ return remove (object , stringToPath (path ));
1799+ }
1800+
1801+ public static <T > T remove (final Map <String , Object > object , final List <String > paths ) {
1802+ return baseGetOrSetOrRemove (object , paths , null , OperationType .REMOVE );
17861803 }
17871804
17881805 public static Map <String , Object > rename (
@@ -2658,6 +2675,43 @@ public static String xmlToJson(String xml, Mode mode) {
26582675 return xmlToJson (xml , Json .JsonStringBuilder .Step .TWO_SPACES , mode );
26592676 }
26602677
2678+ public enum TextType {
2679+ JSON ,
2680+ XML ,
2681+ OTHER
2682+ }
2683+
2684+ public static TextType getTextType (String text ) {
2685+ String trimmed = trim (text );
2686+ final TextType textType ;
2687+ if (trimmed .startsWith ("{" ) && trimmed .endsWith ("}" )
2688+ || trimmed .startsWith ("[" ) && trimmed .endsWith ("]" )) {
2689+ textType = TextType .JSON ;
2690+ } else if (trimmed .startsWith ("<" ) && trimmed .endsWith (">" )) {
2691+ textType = TextType .XML ;
2692+ } else {
2693+ textType = TextType .OTHER ;
2694+ }
2695+ return textType ;
2696+ }
2697+
2698+ public static String formatJsonOrXml (String jsonOrXml , String identStep ) {
2699+ TextType textType = getTextType (jsonOrXml );
2700+ final String result ;
2701+ if (textType == TextType .JSON ) {
2702+ result = formatJson (jsonOrXml , Json .JsonStringBuilder .Step .valueOf (identStep ));
2703+ } else if (textType == TextType .XML ) {
2704+ result = formatXml (jsonOrXml , Xml .XmlStringBuilder .Step .valueOf (identStep ));
2705+ } else {
2706+ result = jsonOrXml ;
2707+ }
2708+ return result ;
2709+ }
2710+
2711+ public static String formatJsonOrXml (String jsonOrXml ) {
2712+ return formatJsonOrXml (jsonOrXml , "TWO_SPACES" );
2713+ }
2714+
26612715 public static String formatJson (String json , Json .JsonStringBuilder .Step identStep ) {
26622716 return Json .formatJson (json , identStep );
26632717 }
@@ -3119,16 +3173,30 @@ public <T> T get(final String path) {
31193173 return U .get (data , path );
31203174 }
31213175
3176+ public <T > T get (final List <String > paths ) {
3177+ return U .get (data , paths );
3178+ }
3179+
31223180 public Builder set (final String path , final Object value ) {
31233181 U .set (data , path , value );
31243182 return this ;
31253183 }
31263184
3185+ public Builder set (final List <String > paths , final Object value ) {
3186+ U .set (data , paths , value );
3187+ return this ;
3188+ }
3189+
31273190 public Builder remove (final String key ) {
31283191 U .remove (data , key );
31293192 return this ;
31303193 }
31313194
3195+ public Builder remove (final List <String > keys ) {
3196+ U .remove (data , keys );
3197+ return this ;
3198+ }
3199+
31323200 public Builder clear () {
31333201 data .clear ();
31343202 return this ;
@@ -3238,6 +3306,13 @@ public <T> T get(final String path) {
32383306 return U .get (U .getStringObjectMap (data ), "value." + path );
32393307 }
32403308
3309+ public <T > T get (final List <String > paths ) {
3310+ List <String > newPaths = new ArrayList <>();
3311+ newPaths .add ("value" );
3312+ newPaths .addAll (paths );
3313+ return U .get (U .getStringObjectMap (data ), newPaths );
3314+ }
3315+
32413316 public ArrayBuilder set (final int index , final Object value ) {
32423317 data .set (index , value );
32433318 return this ;
0 commit comments