@@ -2618,7 +2618,10 @@ public Object fromXml() {
26182618
26192619 @ SuppressWarnings ("unchecked" )
26202620 public static String jsonToXml (
2621- String json , Xml .XmlStringBuilder .Step identStep , JsonToXmlMode mode , String newRootName ) {
2621+ String json ,
2622+ Xml .XmlStringBuilder .Step identStep ,
2623+ JsonToXmlMode mode ,
2624+ String newRootName ) {
26222625 Object object = Json .fromJson (json );
26232626 final String result ;
26242627 if (object instanceof Map ) {
@@ -2670,15 +2673,19 @@ public static String jsonToXml(String json, JsonToXmlMode mode, String newRootNa
26702673
26712674 public static String jsonToXml (String json , String newRootName ) {
26722675 return jsonToXml (
2673- json , Xml .XmlStringBuilder .Step .TWO_SPACES , JsonToXmlMode .DEFINE_ROOT_NAME , newRootName );
2676+ json ,
2677+ Xml .XmlStringBuilder .Step .TWO_SPACES ,
2678+ JsonToXmlMode .DEFINE_ROOT_NAME ,
2679+ newRootName );
26742680 }
26752681
26762682 public static String jsonToXml (String json ) {
26772683 return jsonToXml (json , Xml .XmlStringBuilder .Step .TWO_SPACES , null , null );
26782684 }
26792685
26802686 @ SuppressWarnings ("unchecked" )
2681- public static String xmlToJson (String xml , Json .JsonStringBuilder .Step identStep , XmlToJsonMode mode ) {
2687+ public static String xmlToJson (
2688+ String xml , Json .JsonStringBuilder .Step identStep , XmlToJsonMode mode ) {
26822689 Object object = Xml .fromXml (xml );
26832690 final String result ;
26842691 if (object instanceof Map ) {
@@ -2724,6 +2731,62 @@ public static String xmlToJson(String xml, XmlToJsonMode mode) {
27242731 return xmlToJson (xml , Json .JsonStringBuilder .Step .TWO_SPACES , mode );
27252732 }
27262733
2734+ public static String xmlOrJsonToJson (String xmlOrJson , Json .JsonStringBuilder .Step identStep ) {
2735+ TextType textType = getTextType (xmlOrJson );
2736+ final String result ;
2737+ if (textType == TextType .JSON ) {
2738+ result = getJsonString (identStep , fromJson (xmlOrJson ));
2739+ } else if (textType == TextType .XML ) {
2740+ result = getJsonString (identStep , fromXml (xmlOrJson ));
2741+ } else {
2742+ result = xmlOrJson ;
2743+ }
2744+ return result ;
2745+ }
2746+
2747+ public static String xmlOrJsonToJson (String xmlOrJson ) {
2748+ return xmlOrJsonToJson (xmlOrJson , Json .JsonStringBuilder .Step .TWO_SPACES );
2749+ }
2750+
2751+ @ SuppressWarnings ("unchecked" )
2752+ private static String getJsonString (Json .JsonStringBuilder .Step identStep , Object object ) {
2753+ final String result ;
2754+ if (object instanceof Map ) {
2755+ result = Json .toJson ((Map ) object , identStep );
2756+ } else {
2757+ result = Json .toJson ((List ) object , identStep );
2758+ }
2759+ return result ;
2760+ }
2761+
2762+ public static String xmlOrJsonToXml (String xmlOrJson , Xml .XmlStringBuilder .Step identStep ) {
2763+ TextType textType = getTextType (xmlOrJson );
2764+ final String result ;
2765+ if (textType == TextType .JSON ) {
2766+ result = getXmlString (identStep , fromJson (xmlOrJson ));
2767+ } else if (textType == TextType .XML ) {
2768+ result = getXmlString (identStep , fromXml (xmlOrJson ));
2769+ } else {
2770+ result = xmlOrJson ;
2771+ }
2772+ return result ;
2773+ }
2774+
2775+ public static String xmlOrJsonToXml (String xmlOrJson ) {
2776+ return xmlOrJsonToXml (xmlOrJson , Xml .XmlStringBuilder .Step .TWO_SPACES );
2777+ }
2778+
2779+ @ SuppressWarnings ("unchecked" )
2780+ private static String getXmlString (Xml .XmlStringBuilder .Step identStep , Object object ) {
2781+ final String result ;
2782+ if (object instanceof Map ) {
2783+ result = Xml .toXml ((Map ) object , identStep );
2784+ } else {
2785+ result = Xml .toXml ((List ) object , identStep );
2786+ }
2787+ return result ;
2788+ }
2789+
27272790 public enum TextType {
27282791 JSON ,
27292792 XML ,
0 commit comments