You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2017/02/19 04:04:38 UTC
incubator-atlas git commit: ATLAS-1566: replace GSON ser-de with
ObjectMapper ser-de
Repository: incubator-atlas
Updated Branches:
refs/heads/master ea38942ba -> 8cd6a6445
ATLAS-1566: replace GSON ser-de with ObjectMapper ser-de
Signed-off-by: Madhan Neethiraj <ma...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/8cd6a644
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/8cd6a644
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/8cd6a644
Branch: refs/heads/master
Commit: 8cd6a6445ff59d1345985581e229adc13bc0c7b0
Parents: ea38942
Author: Vimal Sharma <sv...@apache.org>
Authored: Sat Feb 18 20:01:04 2017 -0800
Committer: Madhan Neethiraj <ma...@apache.org>
Committed: Sat Feb 18 20:03:41 2017 -0800
----------------------------------------------------------------------
.../main/java/org/apache/atlas/AtlasClient.java | 27 +++++++++++++++++++
.../java/org/apache/atlas/type/AtlasType.java | 28 +++++++++++++++-----
release-log.txt | 1 +
.../atlas/web/adapters/TestEntitiesREST.java | 11 +++-----
4 files changed, 53 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/8cd6a644/client/src/main/java/org/apache/atlas/AtlasClient.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/atlas/AtlasClient.java b/client/src/main/java/org/apache/atlas/AtlasClient.java
index 1955f2a..13896ce 100755
--- a/client/src/main/java/org/apache/atlas/AtlasClient.java
+++ b/client/src/main/java/org/apache/atlas/AtlasClient.java
@@ -35,6 +35,10 @@ import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.security.UserGroupInformation;
+import org.codehaus.jackson.annotate.JsonAutoDetect;
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
@@ -44,6 +48,9 @@ import org.slf4j.LoggerFactory;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -51,6 +58,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
+import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY;
+
/**
* Client for metadata.
*/
@@ -243,6 +253,11 @@ public class AtlasClient extends AtlasBaseClient {
}
}
+ @JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE)
+ @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+ @JsonIgnoreProperties(ignoreUnknown=true)
+ @XmlRootElement
+ @XmlAccessorType(XmlAccessType.PROPERTY)
public static class EntityResult {
public static final String OP_CREATED = "created";
public static final String OP_UPDATED = "updated";
@@ -274,14 +289,26 @@ public class AtlasClient extends AtlasBaseClient {
return list;
}
+ public Map<String, List<String>> getEntities(){
+ return entities;
+ }
+
+ public void setEntities(Map<String, List<String>> entities){
+ this.entities = entities;
+ }
+
+ @JsonIgnore
public List<String> getCreatedEntities() {
return get(OP_CREATED);
}
+ @JsonIgnore
public List<String> getUpdateEntities() {
return get(OP_UPDATED);
}
+
+ @JsonIgnore
public List<String> getDeletedEntities() {
return get(OP_DELETED);
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/8cd6a644/intg/src/main/java/org/apache/atlas/type/AtlasType.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasType.java b/intg/src/main/java/org/apache/atlas/type/AtlasType.java
index 6d0c357..28d0a07 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasType.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasType.java
@@ -18,22 +18,25 @@
package org.apache.atlas.type;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import java.io.IOException;
import java.util.List;
+
+
/**
* base class that declares interface for all Atlas types.
*/
+
public abstract class AtlasType {
- private static final Gson GSON =
- new GsonBuilder().serializeNulls().setDateFormat(AtlasBaseTypeDef.SERIALIZED_DATE_FORMAT_STR).create();
+ private static final ObjectMapper mapper = new ObjectMapper();
private final String typeName;
private final TypeCategory typeCategory;
@@ -93,12 +96,23 @@ public abstract class AtlasType {
return this;
}
-
public static String toJson(Object obj) {
- return GSON.toJson(obj);
+ String ret;
+ try {
+ ret = mapper.writeValueAsString(obj);
+ }catch (IOException e){
+ ret = null;
+ }
+ return ret;
}
public static <T> T fromJson(String jsonStr, Class<T> type) {
- return GSON.fromJson(jsonStr, type);
+ T ret;
+ try {
+ ret = mapper.readValue(jsonStr, type);
+ }catch (IOException e){
+ ret = null;
+ }
+ return ret;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/8cd6a644/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index 9e17c54..582b71f 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES:
+ATLAS-1566 replace GSON ser-de with ObjectMapper ser-de (svimal2016 via mneethiraj)
ATLAS-1551 auto update of reverse references in V1 API (dkantor)
ATLAS-1565 Create EntityREST endpoints for delete operations (sarathkumarsubramanian via svimal2106)
ATLAS-1547 Added tests for hard delete (mneethiraj)
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/8cd6a644/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java
index 1df9d2f..861e15f 100644
--- a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java
+++ b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java
@@ -17,8 +17,6 @@
*/
package org.apache.atlas.web.adapters;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.RepositoryMetadataModule;
import org.apache.atlas.RequestContext;
@@ -36,6 +34,7 @@ import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.store.bootstrap.AtlasTypeDefStoreInitializer;
import org.apache.atlas.store.AtlasTypeDefStore;
+import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.web.rest.EntityREST;
@@ -254,11 +253,9 @@ public class TestEntitiesREST {
AtlasEntity serDeserEntity(AtlasEntity entity) throws IOException {
//Convert from json to object and back to trigger the case where it gets translated to a map for attributes instead of AtlasEntity
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- String entityJson = mapper.writeValueAsString(entity);
- //JSON from String to Object
- AtlasEntity newEntity = mapper.readValue(entityJson, AtlasEntity.class);
+ String jsonString = AtlasType.toJson(entity);
+ AtlasEntity newEntity = AtlasType.fromJson(jsonString, AtlasEntity.class);
+
return newEntity;
}