Fix asynchronous patch requests
[aai/champ.git] / champ-service / src / main / java / org / onap / champ / event / GraphEventVertex.java
index cc4f493..866c8ae 100644 (file)
  */
 package org.onap.champ.event;
 
+import java.io.IOException;
 import java.util.Map;
-
 import javax.ws.rs.core.Response.Status;
-
 import org.onap.aai.champcore.model.ChampObject;
+import org.onap.champ.entity.ChampObjectDeserializer;
 import org.onap.champ.exception.ChampServiceException;
-
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gson.JsonElement;
@@ -160,7 +161,7 @@ public class GraphEventVertex {
     return graphEventVertex;
 
   }
-  
+
 
   public ChampObject toChampObject() {
     ChampObject.Builder builder = new ChampObject.Builder(this.getType());
@@ -180,4 +181,20 @@ public class GraphEventVertex {
 
   }
 
+  /**
+   * Uses jackson api to convert the json string into a ChampObject.
+   *
+   * @param json
+   * @return
+   * @throws IOException
+   */
+  // Added this method as gson conversion of timestamp properties(create ts and modified ts) differs from the jackson conversion causing failures.
+  public ChampObject toChampObject(String json) throws IOException {
+      ObjectMapper mapper = new ObjectMapper();
+      SimpleModule module = new SimpleModule();
+      module.addDeserializer(ChampObject.class, new ChampObjectDeserializer());
+      mapper.registerModule(module);
+      return mapper.readValue(json, ChampObject.class);
+    }
+
 }