Commit 8cd6a644 by Vimal Sharma Committed by Madhan Neethiraj

ATLAS-1566: replace GSON ser-de with ObjectMapper ser-de

parent ea38942b
......@@ -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);
}
......
......@@ -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;
}
}
......@@ -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)
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment