File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
main/java/com/github/underscore/lodash
test/java/com/github/underscore/lodash Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -2049,6 +2049,19 @@ public Object fromJson() {
20492049 return Json .fromJson (getString ().get ());
20502050 }
20512051
2052+ @ SuppressWarnings ("unchecked" )
2053+ public static Map <String , Object > fromJsonMap (final String string ) {
2054+ final Object object = Json .fromJson (string );
2055+ final Map <String , Object > result ;
2056+ if (object instanceof Map ) {
2057+ result = (Map <String , Object >) object ;
2058+ } else {
2059+ result = newLinkedHashMap ();
2060+ result .put ("value" , object );
2061+ }
2062+ return result ;
2063+ }
2064+
20522065 public String toXml () {
20532066 return Xml .toXml ((Collection ) getIterable ());
20542067 }
Original file line number Diff line number Diff line change @@ -3142,6 +3142,15 @@ public void fromXmlMap() {
31423142 assertEquals ("{}" , U .fromXmlMap (stringXml3 , Xml .FromType .FOR_CONVERT ).toString ());
31433143 }
31443144
3145+ @ SuppressWarnings ("unchecked" )
3146+ @ Test
3147+ public void fromJsonMap () {
3148+ String stringJson = "[]" ;
3149+ assertEquals ("{value=[]}" , U .fromJsonMap (stringJson ).toString ());
3150+ String stringJson2 = "{}" ;
3151+ assertEquals ("{}" , U .fromJsonMap (stringJson2 ).toString ());
3152+ }
3153+
31453154 @ Test (expected = IllegalArgumentException .class )
31463155 public void testDecodeParseXmlErr13 () {
31473156 U .fromXml ("[\" abc\u0010 \" ]" );
You can’t perform that action at this time.
0 commit comments