all
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package id.co.iconpln.apkt.data309.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
|
||||
public class XmlToJsonConverter {
|
||||
public static String convertXmlToJson(String xmlString) throws Exception {
|
||||
// Create an XML mapper
|
||||
XmlMapper xmlMapper = new XmlMapper();
|
||||
|
||||
// Read XML string into JSON
|
||||
JsonNode jsonNode = xmlMapper.readTree(xmlString.getBytes());
|
||||
|
||||
// Create an Object Mapper
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
// Convert JSON node to JSON string
|
||||
return objectMapper.writeValueAsString(jsonNode);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user