File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
main/java/com/github/underscore/lodash
test/java/com/github/underscore/lodash Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -1995,6 +1995,19 @@ public static Object fromXml(final String xml) {
19951995 return Xml .fromXml (xml );
19961996 }
19971997
1998+ @ SuppressWarnings ("unchecked" )
1999+ public static Map <String , Object > fromXmlMap (final String xml ) {
2000+ final Object object = Xml .fromXml (xml );
2001+ final Map <String , Object > result ;
2002+ if (object instanceof Map ) {
2003+ result = (Map <String , Object >) object ;
2004+ } else {
2005+ result = newLinkedHashMap ();
2006+ result .put ("value" , object );
2007+ }
2008+ return result ;
2009+ }
2010+
19982011 public static Object fromXml (final String xml , final Xml .FromType fromType ) {
19992012 return Xml .fromXml (xml , fromType );
20002013 }
Original file line number Diff line number Diff line change @@ -3125,6 +3125,19 @@ public void fromXml() {
31253125 U .fromXml (stringXml );
31263126 }
31273127
3128+ @ SuppressWarnings ("unchecked" )
3129+ @ Test
3130+ public void fromXmlMap () {
3131+ String stringXml =
3132+ "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>"
3133+ + "\n <root empty-array=\" true\" ></root>" ;
3134+ assertEquals ("{value=[]}" , U .fromXmlMap (stringXml ).toString ());
3135+ String stringXml2 =
3136+ "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>"
3137+ + "\n <root></root>" ;
3138+ assertEquals ("{}" , U .fromXmlMap (stringXml2 ).toString ());
3139+ }
3140+
31283141 @ Test (expected = IllegalArgumentException .class )
31293142 public void testDecodeParseXmlErr13 () {
31303143 U .fromXml ("[\" abc\u0010 \" ]" );
You can’t perform that action at this time.
0 commit comments