Skip to content

Commit 86c64dc

Browse files
richardtitzecakoose
authored andcommitted
/metadata parsing: video_info: 'duration' can be null.
Closes dropbox#23
1 parent 74873fc commit 86c64dc

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

src/com/dropbox/core/DbxEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ public VideoInfo read(JsonParser parser)
483483
JsonReader.expectObjectStart(parser);
484484
File.Location location = null;
485485
Date time_taken = null;
486-
long duration = 0;
486+
Long duration = null;
487487
while (parser.getCurrentToken() == JsonToken.FIELD_NAME) {
488488
String fieldName = parser.getCurrentName();
489489
JsonReader.nextToken(parser);
@@ -492,7 +492,7 @@ public VideoInfo read(JsonParser parser)
492492
} else if (fieldName.equals("time_taken")) {
493493
time_taken = JsonDateReader.Dropbox.readOptional(parser);
494494
} else if (fieldName.equals("duration")) {
495-
duration = JsonReader.readUnsignedLong(parser);
495+
duration = JsonReader.UnsignedLongReader.readOptional(parser);
496496
} else {
497497
JsonReader.skipValue(parser);
498498
}

src/com/dropbox/core/json/JsonReader.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ public static void skipValue(JsonParser parser)
131131
// ------------------------------------------------------------------
132132
// Helpers for various types.
133133

134+
public static final JsonReader<Long> UnsignedLongReader = new JsonReader<Long>() {
135+
@Override
136+
public Long read(JsonParser parser)
137+
throws IOException, JsonReadException
138+
{
139+
return readUnsignedLong(parser);
140+
}
141+
};
142+
134143
public static long readUnsignedLong(JsonParser parser)
135144
throws IOException, JsonReadException
136145
{

test/com/dropbox/core/DbxEntryTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public void parseFileWithVideoInfo() throws Exception
7272
public void parseFileWithVideoInfoNullFields() throws Exception
7373
{
7474
DbxEntry.File f = loadJsonResource(DbxEntry.Reader, "file-with-video-info-null-fields.json").asFile();
75+
assertNull(f.videoInfo.duration);
7576
assertNull(f.videoInfo.location);
7677
assertNull(f.videoInfo.timeTaken);
7778
}

test/com/dropbox/core/file-with-video-info-null-fields.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"bytes": 802996,
1111
"modified": "Fri, 20 Mar 2015 17:45:56 +0000",
1212
"video_info": {
13-
"duration": 1000,
13+
"duration": null,
1414
"lat_long": null,
1515
"time_taken": null
1616
},

0 commit comments

Comments
 (0)