Fix serialization of the "key" property
[aai/champ.git] / champ-lib / champ-core / src / main / java / org / onap / aai / champcore / event / envelope / ChampEventHeader.java
index 9ff6deb..3e19aa5 100644 (file)
@@ -27,9 +27,10 @@ import java.time.format.DateTimeFormatter;
 import java.util.Objects;
 import java.util.UUID;
 import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.onap.aai.champcore.event.envelope.util.GsonUtil;
-import com.google.gson.Gson;
-import com.google.gson.annotations.SerializedName;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
 
 public class ChampEventHeader {
 
@@ -50,28 +51,26 @@ public class ChampEventHeader {
         }
     }
 
-    @SerializedName("request-id")
+    @JsonProperty("request-id")
     private String requestId;
 
     private String timestamp;
 
-    @SerializedName("source-name")
+    @JsonProperty("source-name")
     private String sourceName;
 
-    @SerializedName("event-type")
+    @JsonProperty("event-type")
     private String eventType;
 
-    @SerializedName("validation-entity-type")
+    @JsonProperty("validation-entity-type")
     private String validationEntityType;
 
-    @SerializedName("validation-top-entity-type")
+    @JsonProperty("validation-top-entity-type")
     private String validationTopEntityType;
 
-    @SerializedName("entity-link")
+    @JsonProperty("entity-link")
     private String entityLink;
 
-    private static final Gson gson = GsonUtil.createGson();
-
     public static class Builder {
 
         private final EventType eventType;
@@ -127,7 +126,14 @@ public class ChampEventHeader {
      * @return a JSON format string representation of this object.
      */
     public String toJson() {
-        return gson.toJson(this);
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.setSerializationInclusion(Include.NON_NULL);
+
+        try {
+            return mapper.writeValueAsString(this);
+        } catch (JsonProcessingException e) {
+            return "Unmarshallable: " + e.getMessage();
+        }
     }
 
     ///////////////////////////////////////////////////////////////////////////