File tree Expand file tree Collapse file tree 3 files changed +15
-0
lines changed
main/java/com/arangodb/velocypack
test/java/com/arangodb/velocypack Expand file tree Collapse file tree 3 files changed +15
-0
lines changed Original file line number Diff line number Diff line change 11v4.1.2 (2016-11-xx)
22---------------------------
33* fixed GraphEntity for ArangoDatabase.getGraphs() (field name is null)
4+ * added VelocyPack UTC_DATE parsing to Json String (ISO 8601)
45
56v4.1.1 (2016-11-09)
67---------------------------
Original file line number Diff line number Diff line change 2121package com .arangodb .velocypack ;
2222
2323import java .io .IOException ;
24+ import java .text .DateFormat ;
25+ import java .text .SimpleDateFormat ;
2426import java .util .HashMap ;
2527import java .util .Iterator ;
2628import java .util .Map ;
4042 */
4143public class VPackParser {
4244
45+ private static final DateFormat DATE_FORMAT = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );// ISO 8601
4346 private static final char OBJECT_OPEN = '{' ;
4447 private static final char OBJECT_CLOSE = '}' ;
4548 private static final char ARRAY_OPEN = '[' ;
@@ -122,6 +125,8 @@ private void parse(
122125 json .append (JSONValue .toJSONString (value .getAsString ()));
123126 } else if (value .isNumber ()) {
124127 json .append (value .getAsNumber ());
128+ } else if (value .isDate ()) {
129+ json .append (JSONValue .toJSONString (DATE_FORMAT .format (value .getAsDate ())));
125130 } else if (value .isNull ()) {
126131 json .append (NULL );
127132 } else {
Original file line number Diff line number Diff line change 2323import static org .hamcrest .Matchers .is ;
2424import static org .junit .Assert .assertThat ;
2525
26+ import java .util .Date ;
27+
2628import org .json .simple .JSONValue ;
2729import org .junit .Test ;
2830
@@ -445,4 +447,11 @@ public void deserialize(
445447 assertThat (json , is ("{\" a\" :\" a1\" ,\" b\" :\" b\" }" ));
446448 }
447449
450+ @ Test
451+ public void dateToJson () {
452+ final VPackSlice vpack = new VPackBuilder ().add (new Date (1478766992059L )).slice ();
453+ final VPackParser parser = new VPackParser ();
454+ assertThat (parser .toJson (vpack ), is ("\" 2016-11-10T09:36:32.059Z\" " ));
455+ }
456+
448457}
You can’t perform that action at this time.
0 commit comments