feat: xml parse

main
Jonguk. Lim 2 years ago
parent 0faee76a41
commit c288e157a4

@ -594,6 +594,15 @@
<!-- logback --> <!-- logback -->
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220924</version>
</dependency>
<!-- Rest doc --> <!-- Rest doc -->
<dependency> <dependency>
<groupId>org.springframework.restdocs</groupId> <groupId>org.springframework.restdocs</groupId>

@ -4,6 +4,9 @@ import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.json.JSONObject;
import org.json.XML;
import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
@ -158,5 +161,20 @@ public class JsonUtil {
sb.insert(0, '\n'); sb.insert(0, '\n');
return sb.toString(); return sb.toString();
} }
public static void main(String[] args) {
String xmlStr =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<note>\n" +
"<to>Tove</to>\n" +
"<from>Jani</from>\n" +
"<heading>Reminder</heading>\n" +
"<body>Don't forget me this weekend!</body>\n" +
"</note>";
JSONObject json = XML.toJSONObject(xmlStr);
String jsonStr = json.toString(4);
System.out.println(jsonStr);
}
} }

Loading…
Cancel
Save