Skip to content

Commit 8b79cbd

Browse files
author
Mark
committed
added VelocyPack UTC_DATE parsing to Json String (ISO 8601)
1 parent e2ee6a9 commit 8b79cbd

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
v4.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

56
v4.1.1 (2016-11-09)
67
---------------------------

src/main/java/com/arangodb/velocypack/VPackParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
package com.arangodb.velocypack;
2222

2323
import java.io.IOException;
24+
import java.text.DateFormat;
25+
import java.text.SimpleDateFormat;
2426
import java.util.HashMap;
2527
import java.util.Iterator;
2628
import java.util.Map;
@@ -40,6 +42,7 @@
4042
*/
4143
public 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 {

src/test/java/com/arangodb/velocypack/VPackParserTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import static org.hamcrest.Matchers.is;
2424
import static org.junit.Assert.assertThat;
2525

26+
import java.util.Date;
27+
2628
import org.json.simple.JSONValue;
2729
import 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
}

0 commit comments

Comments
 (0)