Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/java/com/onfido/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,14 @@ public LocalDate read(JsonReader in) throws IOException {
case NULL:
in.nextNull();
return null;
default:
case STRING:
String date = in.nextString();
if (date.isEmpty()) {
return null;
}
return LocalDate.parse(date, formatter);
default:
throw new IllegalStateException("Expected STRING or NULL but was " + in.peek());
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/com/onfido/JSONTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.onfido;

import java.time.LocalDate;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class JSONTest {

@Test
public void parsesEmptyDateStringAsNull() {
com.onfido.model.Applicant applicant =
JSON.getGson().fromJson("{\"dob\": \"\"}", com.onfido.model.Applicant.class);

Assertions.assertNull(applicant.getDob());
}
}
Loading