@@ -2887,6 +2887,39 @@ public static void covertJsonToXml(Path path, Path sourceRoot, Path targetRoot,
28872887 fileJsonToXml (path .toAbsolutePath ().toString (), targetPath .toString (), identStep );
28882888 }
28892889
2890+ public static void xmlFolderToJson (
2891+ String xmlFolder , String jsonFolder , Json .JsonStringBuilder .Step identStep )
2892+ throws IOException {
2893+ Path sourceRoot = Paths .get (xmlFolder );
2894+ Path targetRoot = Paths .get (jsonFolder );
2895+ Files .walkFileTree (sourceRoot , new SimpleFileVisitor <>() {
2896+ @ Override
2897+ public FileVisitResult visitFile (Path path , BasicFileAttributes attrs ) throws IOException {
2898+ covertXmlToJson (path , sourceRoot , targetRoot , identStep );
2899+ return FileVisitResult .CONTINUE ;
2900+ }
2901+ });
2902+ }
2903+
2904+ public static void xmlFolderToJson (String xmlFolder , String jsonFolder ) throws IOException {
2905+ xmlFolderToJson (xmlFolder , jsonFolder , Json .JsonStringBuilder .Step .TWO_SPACES );
2906+ }
2907+
2908+ public static void covertXmlToJson (Path path , Path sourceRoot , Path targetRoot ,
2909+ Json .JsonStringBuilder .Step identStep ) throws IOException {
2910+ Path relativePath = sourceRoot .relativize (path );
2911+ String fileName = relativePath .getFileName ().toString ();
2912+ String xmlFileName ;
2913+ if (fileName .endsWith (".xml" )) {
2914+ xmlFileName = fileName .substring (0 , fileName .length () - 4 ) + ".json" ;
2915+ } else {
2916+ return ;
2917+ }
2918+ Path targetPath = targetRoot .resolve (relativePath ).getParent ().resolve (xmlFileName );
2919+ Files .createDirectories (targetPath .getParent ());
2920+ fileXmlToJson (path .toAbsolutePath ().toString (), targetPath .toString (), identStep );
2921+ }
2922+
28902923 public static void streamJsonToXml (
28912924 InputStream jsonInputStream ,
28922925 OutputStream xmlOutputStream ,
0 commit comments