diff options
author | 2018-02-09 09:53:54 +0800 | |
---|---|---|
committer | 2018-02-09 10:37:19 +0800 | |
commit | 37630177bc70661ce86cb12e9af34e8c09893f4d (patch) | |
tree | 83ccafe8389fd8fc504c628a67b3618ac8c222bf /holmes-actions/src/main/java/org/onap | |
parent | a55c700bc3aaab61731d509e4f4c85f40d6330e6 (diff) |
Test Replace Jackson with GSON
Change-Id: Id4c2ed81e7dbd5546940ff50363555336d55b75b
Issue-ID: HOLMES-115
Signed-off-by: YiLi <li.yi101@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/main/java/org/onap')
8 files changed, 50 insertions, 48 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java index ee32be2..4cbd6bf 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java @@ -15,7 +15,7 @@ */
package org.onap.holmes.common.api.entity;
-import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.gson.annotations.SerializedName;
import java.util.Date;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -24,30 +24,27 @@ import lombok.NoArgsConstructor; @NoArgsConstructor
public class AlarmsCorrelation {
- @JsonProperty(value = "ruleid")
+ @SerializedName(value = "ruleid")
private String ruleId;
- @JsonProperty(value = "ruleinfo")
+ @SerializedName(value = "ruleinfo")
private String ruleInfo;
- @JsonProperty(value = "resulttype")
+ @SerializedName(value = "resulttype")
private byte resultType;
- @JsonProperty(value = "createtime")
+ @SerializedName(value = "createtime")
private Date createTime;
- @JsonProperty(value = "parentalarmid")
+ @SerializedName(value = "parentalarmid")
private long parentAlarmId;
- @JsonProperty(value = "childalarmid")
+ @SerializedName(value = "childalarmid")
private long childAlarmId;
- @JsonProperty(defaultValue = "-1")
private long reserve1 = -1;
- @JsonProperty(defaultValue = "-1")
private long reserve2 = -1;
- @JsonProperty(defaultValue = "-1")
private long reserve3 = -1;
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationResult.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationResult.java index 6802696..f3e2562 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationResult.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationResult.java @@ -15,14 +15,12 @@ */
package org.onap.holmes.common.api.entity;
-import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
-import org.onap.holmes.common.api.stat.Alarm;
-
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
+import org.onap.holmes.common.api.stat.Alarm;
@Setter
@Getter
@@ -30,15 +28,11 @@ import lombok.ToString; @ToString
public class CorrelationResult implements Serializable{
- @JsonProperty
private String ruleId;
- @JsonProperty
private long createTimeL;
- @JsonProperty
private byte resultType;
- @JsonProperty
private Alarm[] affectedAlarms;
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java index eb9273a..0343dfa 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java @@ -15,7 +15,7 @@ */
package org.onap.holmes.common.api.entity;
-import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.gson.annotations.SerializedName;
import java.util.Date;
import java.util.Properties;
import lombok.Getter;
@@ -25,35 +25,36 @@ import lombok.Setter; @Setter
public class CorrelationRule {
- @JsonProperty(value = "ruleid")
+ @SerializedName(value = "ruleid")
private String rid;
- @JsonProperty(value = "rulename")
+ @SerializedName(value = "rulename")
private String name;
- @JsonProperty
+
private String description;
- @JsonProperty
+
private int enabled;
- @JsonProperty
+
private long templateID;
+
private String engineID;
- @JsonProperty
+
private String engineType;
- @JsonProperty
+
private String creator;
- @JsonProperty
+
private String modifier;
- @JsonProperty
+
private Properties params;
- @JsonProperty
+
private String content;
- @JsonProperty
+
private String vendor;
- @JsonProperty(value = "createtime")
+ @SerializedName(value = "createtime")
private Date createTime;
- @JsonProperty(value = "updatetime")
+ @SerializedName(value = "updatetime")
private Date updateTime;
- @JsonProperty(value = "package")
+ @SerializedName(value = "package")
private String packageName;
- @JsonProperty(value = "controlloopname")
+ @SerializedName(value = "controlloopname")
private String closedControlLoopName;
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java index d456910..2c2b793 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java @@ -17,7 +17,6 @@ package org.onap.holmes.common.api.entity;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
@@ -27,7 +26,6 @@ import lombok.Setter; @Data
@NoArgsConstructor
@AllArgsConstructor
-@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
@Setter
public class ServiceNode {
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java index 7804082..f5dca01 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java @@ -16,7 +16,6 @@ package org.onap.holmes.common.api.entity;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
@@ -28,7 +27,6 @@ import lombok.Setter; @Data
@NoArgsConstructor
@AllArgsConstructor
-@JsonIgnoreProperties(ignoreUnknown = true)
@Setter
@Getter
public class ServiceRegisterEntity {
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java index 65058c5..240f09b 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java @@ -15,7 +15,6 @@ */ package org.onap.holmes.common.dmaap; -import com.fasterxml.jackson.core.JsonProcessingException; import java.util.Optional; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -31,7 +30,7 @@ import org.onap.holmes.common.dcae.DcaeConfigurationsCache; import org.onap.holmes.common.dmaap.entity.PolicyMsg; import org.onap.holmes.common.dmaap.entity.PolicyMsg.EVENT_STATUS; import org.onap.holmes.common.exception.CorrelationException; -import org.onap.holmes.common.utils.JacksonUtil; +import org.onap.holmes.common.utils.GsonUtil; @Slf4j @Service @@ -48,11 +47,9 @@ public class DmaapService { publisher.setUrl(DcaeConfigurationsCache.getPubSecInfo(dmaapConfigKey).getDmaapInfo() .getTopicUrl()); publisher.publish(policyMsg); - log.info("send policyMsg: " + JacksonUtil.beanToJson(policyMsg)); + log.info("send policyMsg: " + GsonUtil.beanToJson(policyMsg)); } catch (CorrelationException e) { log.error("Failed to publish the control loop event to DMaaP", e); - } catch (JsonProcessingException e) { - log.info("Failed to convert the control loop event to json"); } catch (NullPointerException e) { log.error("DMaaP configurations do not exist!"); } diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/GsonUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/GsonUtil.java index 6f6e8f3..452aaf8 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/GsonUtil.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/GsonUtil.java @@ -16,20 +16,39 @@ package org.onap.holmes.common.utils; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; import com.google.gson.reflect.TypeToken; +import java.lang.reflect.Type; import java.util.List; import java.util.Map; public class GsonUtil { private static Gson gson = null; static { - if (gson == null) {; - gson = new Gson(); + if (gson == null) { + gson = new GsonBuilder() + .registerTypeAdapter(Integer.class, new JsonDeserializer<Integer>() { + @Override + public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + try { + return json.getAsInt(); + } catch (NumberFormatException e) { + return 0; + } + } + }) + .create(); } } private GsonUtil() { } + + public static String beanToJson(Object object) { String gsonString = null; if (gson != null) { diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/Md5Util.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/Md5Util.java index 1c06b52..c630239 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/Md5Util.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/Md5Util.java @@ -16,12 +16,10 @@ package org.onap.holmes.common.utils; -import com.fasterxml.jackson.core.JsonProcessingException; import com.google.common.hash.HashCode; import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; import java.nio.charset.Charset; -import net.sf.json.JSONObject; public class Md5Util { @@ -38,8 +36,8 @@ public class Md5Util { return hash.toString(); } - public static String md5(Object data) throws JsonProcessingException { - String actualData = data == null ? "{}" : JacksonUtil.beanToJson(data); + public static String md5(Object data) { + String actualData = data == null ? "{}" : GsonUtil.beanToJson(data); return md5(actualData); } } |