Commit 5f58dcce authored by Spiros Koulouzis's avatar Spiros Koulouzis

Added yml / json converters

parent acb0dfb1
......@@ -22,7 +22,6 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
......@@ -59,7 +58,7 @@ public class UploadToscaController {
PlannerCaller planner = null;
if (!file.isEmpty()) {
try {
String originalFileName = file.getOriginalFilename();
String name = System.currentTimeMillis() + "_" + originalFileName;
......
......@@ -31,7 +31,6 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.6</version>
<scope>test</scope>
</dependency>
<dependency>
......@@ -39,10 +38,13 @@
<artifactId>json</artifactId>
<version>20090211</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.17</version>
<type>jar</type>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
......
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.commons.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import org.yaml.snakeyaml.Yaml;
/**
*
* @author S. Koulouzis
*/
public class Converter {
public static String yml2Json(String yamlString) {
Yaml yaml = new Yaml();
Map<String, Object> map = (Map<String, Object>) yaml.load(yamlString);
JSONObject jsonObject = new JSONObject(map);
return jsonObject.toString();
}
public static String json2Yml2(String jsonString) throws JSONException {
Yaml yaml = new Yaml();
Map<String, Object> map = (Map<String, Object>) yaml.load(jsonString);
return yaml.dump(map);
}
}
......@@ -28,7 +28,6 @@ import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment