diff options
author | 2018-03-21 09:30:16 +0800 | |
---|---|---|
committer | 2018-03-21 09:30:16 +0800 | |
commit | 70410b3ef0fd4c2325431436365be82c2663a5ed (patch) | |
tree | 9b11b8c8f1e513daf0988fe4935bc8c568db9062 /sdc-workflow-designer-server/src/main/java/org/onap | |
parent | 821c6300e715b354c421b3329809dfc906c67c87 (diff) |
JsonUtils for JSON format.
JsonUtils for JSON format.
Issue-ID: SDC-1079
Change-Id: I8879652751a0c0ae9d2597e33997fc32a9baa816
Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
Diffstat (limited to 'sdc-workflow-designer-server/src/main/java/org/onap')
3 files changed, 61 insertions, 5 deletions
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResource.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResource.java index 10269a37..600ec8ca 100644 --- a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResource.java +++ b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResource.java @@ -26,12 +26,12 @@ import org.eclipse.jetty.http.HttpStatus; import org.onap.sdc.workflowdesigner.resources.entity.ExtActivityDisplayInfo; import org.onap.sdc.workflowdesigner.resources.entity.ExtendActivity; import org.onap.sdc.workflowdesigner.utils.FileCommonUtils; +import org.onap.sdc.workflowdesigner.utils.JsonUtils; import org.onap.sdc.workflowdesigner.utils.RestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.codahale.metrics.annotation.Timed; -import com.google.gson.Gson; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -90,8 +90,7 @@ public class ExtendActivityResource { */ private ExtendActivity[] retriveExtActivites(String sence) throws IOException { String json = FileCommonUtils.readString(EXT_ACTIVITIES_FILE_NAME); - Gson gson = new Gson(); - return gson.fromJson(json, ExtendActivity[].class); + return JsonUtils.fromJson(json, ExtendActivity[].class); } @@ -125,8 +124,7 @@ public class ExtendActivityResource { */ private ExtActivityDisplayInfo retriveDisplayInfo(String sence) throws IOException { String json = FileCommonUtils.readString(EXT_ACTIVITIES_DISPLAY_INFO_FILE_NAME); - Gson gson = new Gson(); - return gson.fromJson(json, ExtActivityDisplayInfo.class); + return JsonUtils.fromJson(json, ExtActivityDisplayInfo.class); } } diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/entity/I18nString.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/entity/I18nString.java index 1dc880d8..1ed14f6f 100644 --- a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/entity/I18nString.java +++ b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/entity/I18nString.java @@ -20,6 +20,23 @@ public class I18nString { private String zh_CN;
/**
+ *
+ */
+ public I18nString() {
+ super();
+ }
+
+ /**
+ * @param en_US
+ * @param zh_CN
+ */
+ public I18nString(String en_US, String zh_CN) {
+ super();
+ this.en_US = en_US;
+ this.zh_CN = zh_CN;
+ }
+
+ /**
* @return the en_US
*/
public String getEn_US() {
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/JsonUtils.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/JsonUtils.java new file mode 100644 index 00000000..09588ef3 --- /dev/null +++ b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/JsonUtils.java @@ -0,0 +1,41 @@ +/**
+ * Copyright (c) 2018 ZTE Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the Apache License, Version 2.0
+ * and the Eclipse Public License v1.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * ZTE - initial API and implementation and/or initial documentation
+ */
+package org.onap.sdc.workflowdesigner.utils;
+
+import com.google.gson.Gson;
+
+/**
+ *
+ */
+public class JsonUtils {
+ /**
+ *
+ * @param json
+ * @param clazz
+ * @return
+ */
+ public static <T> T fromJson(String json, Class<T> clazz) {
+ Gson gson = new Gson();
+ return gson.fromJson(json, clazz);
+ }
+
+ /**
+ *
+ * @param t
+ * @return
+ */
+ public static <T> String toJson(T t) {
+ Gson gson = new Gson();
+ return gson.toJson(t);
+ }
+
+}
|