@@ -127,13 +127,13 @@ private static Class<?> getParameterized() {
127
127
return holder .get ();
128
128
}
129
129
130
- // private static boolean hasNextParameterized() {
131
- // ClassHolder holder = parameterizedBridger.get();
132
- // if (holder == null) {
133
- // return false;
134
- // }
135
- // return holder.hasNext();
136
- // }
130
+ private static boolean hasNextParameterized () {
131
+ ClassHolder holder = parameterizedBridger .get ();
132
+ if (holder == null ) {
133
+ return false ;
134
+ }
135
+ return holder .hasNext ();
136
+ }
137
137
138
138
private static Class <?> nextParameterized () {
139
139
ClassHolder holder = parameterizedBridger .get ();
@@ -1907,4 +1907,120 @@ public EdgeEntity<?> deserialize(JsonElement json, Type typeOfT, JsonDeserializa
1907
1907
1908
1908
}
1909
1909
1910
+ public static class TraversalEntityDeserializer implements JsonDeserializer <TraversalEntity <?, ?>> {
1911
+ @ Override
1912
+ public TraversalEntity <?, ?> deserialize (JsonElement json , Type typeOfT , JsonDeserializationContext context )
1913
+ throws JsonParseException {
1914
+
1915
+ if (json .isJsonNull ()) {
1916
+ return null ;
1917
+ }
1918
+
1919
+ JsonObject obj = json .getAsJsonObject ();
1920
+ TraversalEntity <Object , Object > entity = deserializeBaseParameter (obj ,
1921
+ new TraversalEntity <Object , Object >());
1922
+ deserializeDocumentParameter (obj , entity );
1923
+
1924
+ if (obj .has ("result" )) {
1925
+ JsonObject result = obj .getAsJsonObject ("result" );
1926
+ if (result .has ("visited" )) {
1927
+ JsonObject visited = result .getAsJsonObject ("visited" );
1928
+ VisitedEntity <Object , Object > v = (VisitedEntity <Object , Object >) context .deserialize (visited ,
1929
+ VisitedEntity .class );
1930
+ entity .setEntity (v );
1931
+ }
1932
+ }
1933
+
1934
+ return entity ;
1935
+ }
1936
+
1937
+ }
1938
+
1939
+ public static class VisitedEntityDeserializer implements JsonDeserializer <VisitedEntity <?, ?>> {
1940
+ @ Override
1941
+ public VisitedEntity <?, ?> deserialize (JsonElement json , Type typeOfT , JsonDeserializationContext context )
1942
+ throws JsonParseException {
1943
+
1944
+ if (json .isJsonNull ()) {
1945
+ return null ;
1946
+ }
1947
+
1948
+ JsonObject visited = json .getAsJsonObject ();
1949
+ VisitedEntity <Object , Object > entity = new VisitedEntity <Object , Object >();
1950
+
1951
+ Class <?> vertexClazz = getParameterized ();
1952
+ Class <?> edgeClazz = null ;
1953
+ if (hasNextParameterized ()) {
1954
+ edgeClazz = nextParameterized ();
1955
+ }
1956
+
1957
+ if (visited .has ("vertices" )) {
1958
+ entity .setVertices (getVertices (vertexClazz , context , visited .getAsJsonArray ("vertices" )));
1959
+ }
1960
+ if (visited .has ("paths" )) {
1961
+ List <PathEntity <Object , Object >> pathEntities = new ArrayList <PathEntity <Object , Object >>();
1962
+ JsonArray paths = visited .getAsJsonArray ("paths" );
1963
+ if (!paths .equals (null )) {
1964
+ for (int i = 0 , imax = paths .size (); i < imax ; i ++) {
1965
+ JsonObject path = paths .get (i ).getAsJsonObject ();
1966
+ PathEntity <Object , Object > pathEntity = new PathEntity <Object , Object >();
1967
+
1968
+ if (path .has ("edges" )) {
1969
+ pathEntity .setEdges (getEdges (edgeClazz , context , path .getAsJsonArray ("edges" )));
1970
+ }
1971
+ if (path .has ("vertices" )) {
1972
+ pathEntity .setVertices (getVertices (vertexClazz , context , path .getAsJsonArray ("vertices" )));
1973
+ }
1974
+
1975
+ pathEntities .add (pathEntity );
1976
+ }
1977
+ }
1978
+ entity .setPaths (pathEntities );
1979
+ }
1980
+
1981
+ return entity ;
1982
+ }
1983
+ }
1984
+
1985
+ private static List <VertexEntity <Object >> getVertices (
1986
+ Class <?> vertexClazz ,
1987
+ JsonDeserializationContext context ,
1988
+ JsonArray vertices ) {
1989
+ List <VertexEntity <Object >> list = new ArrayList <VertexEntity <Object >>();
1990
+ if (!vertices .equals (null )) {
1991
+ for (int i = 0 , imax = vertices .size (); i < imax ; i ++) {
1992
+ JsonObject vertex = vertices .get (i ).getAsJsonObject ();
1993
+ VertexEntity <Object > ve = deserializeBaseParameter (vertex , new VertexEntity <Object >());
1994
+ deserializeDocumentParameter (vertex , ve );
1995
+ if (vertexClazz != null ) {
1996
+ ve .setEntity (context .deserialize (vertex , vertexClazz ));
1997
+ } else {
1998
+ ve .setEntity (context .deserialize (vertex , Object .class ));
1999
+ }
2000
+ list .add (ve );
2001
+ }
2002
+ }
2003
+ return list ;
2004
+ }
2005
+
2006
+ private static List <EdgeEntity <Object >> getEdges (
2007
+ Class <?> edgeClazz ,
2008
+ JsonDeserializationContext context ,
2009
+ JsonArray edges ) {
2010
+ List <EdgeEntity <Object >> list = new ArrayList <EdgeEntity <Object >>();
2011
+ if (!edges .equals (null )) {
2012
+ for (int i = 0 , imax = edges .size (); i < imax ; i ++) {
2013
+ JsonObject edge = edges .get (i ).getAsJsonObject ();
2014
+ EdgeEntity <Object > ve = deserializeBaseParameter (edge , new EdgeEntity <Object >());
2015
+ deserializeDocumentParameter (edge , ve );
2016
+ if (edgeClazz != null ) {
2017
+ ve .setEntity (context .deserialize (edge , edgeClazz ));
2018
+ } else {
2019
+ ve .setEntity (context .deserialize (edge , Object .class ));
2020
+ }
2021
+ list .add (ve );
2022
+ }
2023
+ }
2024
+ return list ;
2025
+ }
1910
2026
}
0 commit comments