@@ -1908,6 +1908,7 @@ public EdgeEntity<?> deserialize(JsonElement json, Type typeOfT, JsonDeserializa
19081908 }
19091909
19101910 public static class TraversalEntityDeserializer implements JsonDeserializer <TraversalEntity <?, ?>> {
1911+ @ SuppressWarnings ("unchecked" )
19111912 @ Override
19121913 public TraversalEntity <?, ?> deserialize (JsonElement json , Type typeOfT , JsonDeserializationContext context )
19131914 throws JsonParseException {
@@ -1923,31 +1924,35 @@ public static class TraversalEntityDeserializer implements JsonDeserializer<Trav
19231924
19241925 if (obj .has ("result" )) {
19251926 JsonObject result = obj .getAsJsonObject ("result" );
1927+ TraversalResultEntity <Object , Object > v = null ;
1928+
19261929 if (result .has ("visited" )) {
19271930 JsonObject visited = result .getAsJsonObject ("visited" );
1928- @ SuppressWarnings ( "unchecked" )
1929- VisitedEntity < Object , Object > v = ( VisitedEntity < Object , Object >) context . deserialize ( visited ,
1930- VisitedEntity . class );
1931- entity . setEntity ( v );
1931+ v = ( TraversalResultEntity < Object , Object >) context . deserialize ( visited ,
1932+ TraversalResultEntity . class );
1933+ } else {
1934+ v = new TraversalResultEntity < Object , Object >( );
19321935 }
1936+ entity .setEntity (v );
19331937 }
19341938
19351939 return entity ;
19361940 }
1937-
19381941 }
19391942
1940- public static class VisitedEntityDeserializer implements JsonDeserializer <VisitedEntity <?, ?>> {
1943+ public static class TraversalResultEntityDeserializer implements JsonDeserializer <TraversalResultEntity <?, ?>> {
19411944 @ Override
1942- public VisitedEntity <?, ?> deserialize (JsonElement json , Type typeOfT , JsonDeserializationContext context )
1943- throws JsonParseException {
1945+ public TraversalResultEntity <?, ?> deserialize (
1946+ JsonElement json ,
1947+ Type typeOfT ,
1948+ JsonDeserializationContext context ) throws JsonParseException {
19441949
19451950 if (json .isJsonNull ()) {
19461951 return null ;
19471952 }
19481953
19491954 JsonObject visited = json .getAsJsonObject ();
1950- VisitedEntity <Object , Object > entity = new VisitedEntity <Object , Object >();
1955+ TraversalResultEntity <Object , Object > entity = new TraversalResultEntity <Object , Object >();
19511956
19521957 Class <?> vertexClazz = getParameterized ();
19531958 Class <?> edgeClazz = null ;
@@ -1959,28 +1964,107 @@ public static class VisitedEntityDeserializer implements JsonDeserializer<Visite
19591964 entity .setVertices (getVertices (vertexClazz , context , visited .getAsJsonArray ("vertices" )));
19601965 }
19611966 if (visited .has ("paths" )) {
1962- List <PathEntity <Object , Object >> pathEntities = new ArrayList <PathEntity <Object , Object >>();
1963- JsonArray paths = visited .getAsJsonArray ("paths" );
1964- if (!paths .equals (null )) {
1965- for (int i = 0 , imax = paths .size (); i < imax ; i ++) {
1966- JsonObject path = paths .get (i ).getAsJsonObject ();
1967- PathEntity <Object , Object > pathEntity = new PathEntity <Object , Object >();
1968-
1969- if (path .has ("edges" )) {
1970- pathEntity .setEdges (getEdges (edgeClazz , context , path .getAsJsonArray ("edges" )));
1971- }
1972- if (path .has ("vertices" )) {
1973- pathEntity .setVertices (getVertices (vertexClazz , context , path .getAsJsonArray ("vertices" )));
1974- }
1967+ entity .setPaths (getPaths (context , visited , vertexClazz , edgeClazz ));
1968+ }
19751969
1976- pathEntities .add (pathEntity );
1977- }
1970+ return entity ;
1971+ }
1972+ }
1973+
1974+ public static class ShortestPathEntityDeserializer implements JsonDeserializer <ShortestPathEntity <?, ?>> {
1975+ @ SuppressWarnings ("unchecked" )
1976+ @ Override
1977+ public ShortestPathEntity <?, ?> deserialize (JsonElement json , Type typeOfT , JsonDeserializationContext context )
1978+ throws JsonParseException {
1979+
1980+ if (json .isJsonNull ()) {
1981+ return null ;
1982+ }
1983+
1984+ JsonObject obj = json .getAsJsonObject ();
1985+ ShortestPathEntity <Object , Object > entity = deserializeBaseParameter (obj ,
1986+ new ShortestPathEntity <Object , Object >());
1987+ deserializeDocumentParameter (obj , entity );
1988+
1989+ if (obj .has ("result" )) {
1990+ JsonArray result = obj .getAsJsonArray ("result" );
1991+ ShortestPathResultEntity <Object , Object > v = null ;
1992+
1993+ if (result .size () > 0 ) {
1994+ v = (ShortestPathResultEntity <Object , Object >) context .deserialize (result .get (0 ),
1995+ ShortestPathResultEntity .class );
1996+ } else {
1997+ v = new ShortestPathResultEntity <Object , Object >();
19781998 }
1979- entity .setPaths (pathEntities );
1999+ entity .setEntity (v );
2000+ }
2001+
2002+ return entity ;
2003+ }
2004+ }
2005+
2006+ public static class ShortestPathResultEntityDeserializer implements
2007+ JsonDeserializer <ShortestPathResultEntity <?, ?>> {
2008+ @ Override
2009+ public ShortestPathResultEntity <?, ?> deserialize (
2010+ JsonElement json ,
2011+ Type typeOfT ,
2012+ JsonDeserializationContext context ) throws JsonParseException {
2013+
2014+ if (json .isJsonNull ()) {
2015+ return null ;
2016+ }
2017+
2018+ JsonObject visited = json .getAsJsonObject ();
2019+ ShortestPathResultEntity <Object , Object > entity = new ShortestPathResultEntity <Object , Object >();
2020+
2021+ Class <?> vertexClazz = getParameterized ();
2022+ Class <?> edgeClazz = null ;
2023+ if (hasNextParameterized ()) {
2024+ edgeClazz = nextParameterized ();
2025+ }
2026+
2027+ if (visited .has ("vertex" )) {
2028+ entity .setVertex (getVertex (context , visited .getAsJsonObject ("vertex" ), vertexClazz ));
2029+ }
2030+ if (visited .has ("distance" )) {
2031+ entity .setDistance (visited .get ("distance" ).getAsLong ());
2032+ }
2033+ if (visited .has ("startVertex" )) {
2034+ entity .setStartVertex (visited .get ("startVertex" ).getAsString ());
2035+ }
2036+ if (visited .has ("paths" )) {
2037+ entity .setPaths (getPaths (context , visited , vertexClazz , edgeClazz ));
19802038 }
19812039
19822040 return entity ;
19832041 }
2042+
2043+ }
2044+
2045+ private static List <PathEntity <Object , Object >> getPaths (
2046+ JsonDeserializationContext context ,
2047+ JsonObject visited ,
2048+ Class <?> vertexClazz ,
2049+ Class <?> edgeClazz ) {
2050+ List <PathEntity <Object , Object >> pathEntities = new ArrayList <PathEntity <Object , Object >>();
2051+ JsonArray paths = visited .getAsJsonArray ("paths" );
2052+ if (!paths .equals (null )) {
2053+ for (int i = 0 , imax = paths .size (); i < imax ; i ++) {
2054+ JsonObject path = paths .get (i ).getAsJsonObject ();
2055+ PathEntity <Object , Object > pathEntity = new PathEntity <Object , Object >();
2056+
2057+ if (path .has ("edges" )) {
2058+ pathEntity .setEdges (getEdges (edgeClazz , context , path .getAsJsonArray ("edges" )));
2059+ }
2060+ if (path .has ("vertices" )) {
2061+ pathEntity .setVertices (getVertices (vertexClazz , context , path .getAsJsonArray ("vertices" )));
2062+ }
2063+
2064+ pathEntities .add (pathEntity );
2065+ }
2066+ }
2067+ return pathEntities ;
19842068 }
19852069
19862070 private static List <VertexEntity <Object >> getVertices (
@@ -1991,19 +2075,27 @@ private static List<VertexEntity<Object>> getVertices(
19912075 if (!vertices .equals (null )) {
19922076 for (int i = 0 , imax = vertices .size (); i < imax ; i ++) {
19932077 JsonObject vertex = vertices .get (i ).getAsJsonObject ();
1994- VertexEntity <Object > ve = deserializeBaseParameter (vertex , new VertexEntity <Object >());
1995- deserializeDocumentParameter (vertex , ve );
1996- if (vertexClazz != null ) {
1997- ve .setEntity (context .deserialize (vertex , vertexClazz ));
1998- } else {
1999- ve .setEntity (context .deserialize (vertex , Object .class ));
2000- }
2078+ VertexEntity <Object > ve = getVertex (context , vertex , vertexClazz );
20012079 list .add (ve );
20022080 }
20032081 }
20042082 return list ;
20052083 }
20062084
2085+ private static VertexEntity <Object > getVertex (
2086+ JsonDeserializationContext context ,
2087+ JsonObject vertex ,
2088+ Class <?> vertexClazz ) {
2089+ VertexEntity <Object > ve = deserializeBaseParameter (vertex , new VertexEntity <Object >());
2090+ deserializeDocumentParameter (vertex , ve );
2091+ if (vertexClazz != null ) {
2092+ ve .setEntity (context .deserialize (vertex , vertexClazz ));
2093+ } else {
2094+ ve .setEntity (context .deserialize (vertex , Object .class ));
2095+ }
2096+ return ve ;
2097+ }
2098+
20072099 private static List <EdgeEntity <Object >> getEdges (
20082100 Class <?> edgeClazz ,
20092101 JsonDeserializationContext context ,
0 commit comments