forked from AY2324S2-CS2103T-T08-1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Json Classes to accept new format. Update data json files to account for new format. Create OptionalSerializer to force null values to be formatted properly
- Loading branch information
1 parent
19c1404
commit db359dd
Showing
8 changed files
with
268 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/seedu/address/commons/util/OptionalSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package seedu.address.commons.util; | ||
|
||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
|
||
/** | ||
* A Serializer for handling Optional values and converting them into | ||
* proper JSON strings with correct null formatting. | ||
*/ | ||
public class OptionalSerializer extends JsonSerializer<Optional<?>> { | ||
@Override | ||
public void serialize(Optional<?> optional, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) | ||
throws IOException { | ||
if (optional.isPresent()) { | ||
jsonGenerator.writeObject(optional.get()); | ||
} else { | ||
jsonGenerator.writeNull(); | ||
} | ||
} | ||
/** | ||
* Avoids directly specifying Optional.class with generics | ||
*/ | ||
public Class<Optional<?>> handledType() { | ||
return (Class<Optional<?>>) (Class<?>) Optional.class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 36 additions & 11 deletions
47
src/test/data/JsonAddressBookStorageTest/invalidAndValidPersonAddressBook.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,38 @@ | ||
{ | ||
"persons": [ { | ||
"name": "Valid Person", | ||
"phone": "9482424", | ||
"email": "[email protected]", | ||
"address": "4th street" | ||
}, { | ||
"name": "Person With Invalid Phone Field", | ||
"phone": "948asdf2424", | ||
"email": "[email protected]", | ||
"address": "4th street" | ||
} ] | ||
"persons": [ | ||
{ | ||
"nric": "T0139571B", | ||
"name": "Valid Person", | ||
"phone": "94351253", | ||
"address": "123, Jurong West Ave 6, #08-111", | ||
"dateOfBirth": "2001-01-01", | ||
"sex": "F", | ||
"status": "HEALTHY", | ||
"email": null, | ||
"country": null, | ||
"allergies": null, | ||
"bloodType": null, | ||
"condition": null, | ||
"dateOfAdmission": null, | ||
"diagnosis": null, | ||
"symptom": null | ||
}, | ||
{ | ||
"nric": "T0139571B", | ||
"name": "Invalid Person Phone Wrong", | ||
"phone": "94eeqa!1253a", | ||
"address": "123, Jurong West Ave 6, #08-111", | ||
"dateOfBirth": "2001-01-01", | ||
"sex": "F", | ||
"status": "HEALTHY", | ||
"email": null, | ||
"country": null, | ||
"allergies": null, | ||
"bloodType": null, | ||
"condition": null, | ||
"dateOfAdmission": null, | ||
"diagnosis": null, | ||
"symptom": null | ||
} | ||
] | ||
} |
25 changes: 19 additions & 6 deletions
25
src/test/data/JsonAddressBookStorageTest/invalidPersonAddressBook.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
{ | ||
"persons": [ { | ||
"name": "Person with invalid name field: Ha!ns Mu@ster", | ||
"phone": "9482424", | ||
"email": "[email protected]", | ||
"address": "4th street" | ||
} ] | ||
"persons": [ | ||
{ | ||
"nric": "INVALID NRIC!!!!", | ||
"name": "Alice Pauline", | ||
"phone": "94351253", | ||
"address": "123, Jurong West Ave 6, #08-111", | ||
"dateOfBirth": "2001-01-01", | ||
"sex": "F", | ||
"status": "HEALTHY", | ||
"email": null, | ||
"country": null, | ||
"allergies": null, | ||
"bloodType": null, | ||
"condition": null, | ||
"dateOfAdmission": null, | ||
"diagnosis": null, | ||
"symptom": null | ||
} | ||
] | ||
} |
48 changes: 36 additions & 12 deletions
48
src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,38 @@ | ||
{ | ||
"persons": [ { | ||
"name": "Alice Pauline", | ||
"phone": "94351253", | ||
"email": "[email protected]", | ||
"address": "123, Jurong West Ave 6, #08-111", | ||
"tags": [ "friends" ] | ||
}, { | ||
"name": "Alice Pauline", | ||
"phone": "94351253", | ||
"email": "[email protected]", | ||
"address": "4th street" | ||
} ] | ||
"persons": [ | ||
{ | ||
"nric": "T0139571B", | ||
"name": "Alice Pauline", | ||
"phone": "94351253", | ||
"address": "123, Jurong West Ave 6, #08-111", | ||
"dateOfBirth": "2001-01-01", | ||
"sex": "F", | ||
"status": "HEALTHY", | ||
"email": null, | ||
"country": null, | ||
"allergies": null, | ||
"bloodType": null, | ||
"condition": null, | ||
"dateOfAdmission": null, | ||
"diagnosis": null, | ||
"symptom": null | ||
}, | ||
{ | ||
"nric": "T0139571B", | ||
"name": "Alice Pauline", | ||
"phone": "94351253", | ||
"address": "123, Jurong West Ave 6, #08-111", | ||
"dateOfBirth": "2001-01-01", | ||
"sex": "F", | ||
"status": "HEALTHY", | ||
"email": null, | ||
"country": null, | ||
"allergies": null, | ||
"bloodType": null, | ||
"condition": null, | ||
"dateOfAdmission": null, | ||
"diagnosis": null, | ||
"symptom": null | ||
} | ||
] | ||
} |
24 changes: 18 additions & 6 deletions
24
src/test/data/JsonSerializableAddressBookTest/invalidPersonAddressBook.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
{ | ||
"persons": [ { | ||
"name": "Hans Muster", | ||
"phone": "9482424", | ||
"email": "invalid@email!3e", | ||
"address": "4th street" | ||
} ] | ||
"persons": [ | ||
{ | ||
"name": "Hans Muster", | ||
"phone": "94820a", | ||
"address": "4th street", | ||
"dateOfBirth": "2001-01-01", | ||
"sex": "M", | ||
"status": "HEALTHY", | ||
"email": null, | ||
"country": null, | ||
"allergies": null, | ||
"bloodType": null, | ||
"condition": null, | ||
"dateOfAdmission": null, | ||
"diagnosis": null, | ||
"symptom": null | ||
} | ||
] | ||
} |
164 changes: 121 additions & 43 deletions
164
src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,124 @@ | ||
{ | ||
"_comment": "AddressBook save file which contains the same Person values as in TypicalPersons#getTypicalAddressBook()", | ||
"persons" : [ { | ||
"name" : "Alice Pauline", | ||
"phone" : "94351253", | ||
"email" : "[email protected]", | ||
"address" : "123, Jurong West Ave 6, #08-111", | ||
"tags" : [ "friends" ] | ||
}, { | ||
"name" : "Benson Meier", | ||
"phone" : "98765432", | ||
"email" : "[email protected]", | ||
"address" : "311, Clementi Ave 2, #02-25", | ||
"tags" : [ "owesMoney", "friends" ] | ||
}, { | ||
"name" : "Carl Kurz", | ||
"phone" : "95352563", | ||
"email" : "[email protected]", | ||
"address" : "wall street", | ||
"tags" : [ ] | ||
}, { | ||
"name" : "Daniel Meier", | ||
"phone" : "87652533", | ||
"email" : "[email protected]", | ||
"address" : "10th street", | ||
"tags" : [ "friends" ] | ||
}, { | ||
"name" : "Elle Meyer", | ||
"phone" : "9482224", | ||
"email" : "[email protected]", | ||
"address" : "michegan ave", | ||
"tags" : [ ] | ||
}, { | ||
"name" : "Fiona Kunz", | ||
"phone" : "9482427", | ||
"email" : "[email protected]", | ||
"address" : "little tokyo", | ||
"tags" : [ ] | ||
}, { | ||
"name" : "George Best", | ||
"phone" : "9482442", | ||
"email" : "[email protected]", | ||
"address" : "4th street", | ||
"tags" : [ ] | ||
} ] | ||
"persons": [ | ||
{ | ||
"nric": "T0139571B", | ||
"name": "Alice Pauline", | ||
"phone": "94351253", | ||
"address": "123, Jurong West Ave 6, #08-111", | ||
"dateOfBirth": "2001-01-01", | ||
"sex": "F", | ||
"status": "HEALTHY", | ||
"email": null, | ||
"country": null, | ||
"allergies": null, | ||
"bloodType": null, | ||
"condition": null, | ||
"dateOfAdmission": null, | ||
"diagnosis": null, | ||
"symptom": null | ||
}, | ||
{ | ||
"nric": "T0439571C", | ||
"name": "Benson Meier", | ||
"phone": "98765432", | ||
"address": "311, Clementi Ave 2, #02-25", | ||
"dateOfBirth": "2001-01-01", | ||
"sex": "M", | ||
"status": "UNWELL", | ||
"email": null, | ||
"country": null, | ||
"allergies": null, | ||
"bloodType": null, | ||
"condition": null, | ||
"dateOfAdmission": null, | ||
"diagnosis": null, | ||
"symptom": null | ||
}, | ||
{ | ||
"nric": "T0284994B", | ||
"name": "Carl Kurz", | ||
"phone": "95352563", | ||
"address": "wall street", | ||
"dateOfBirth": "2001-01-01", | ||
"sex": "M", | ||
"status": "PENDING", | ||
"email": null, | ||
"country": null, | ||
"allergies": null, | ||
"bloodType": null, | ||
"condition": null, | ||
"dateOfAdmission": null, | ||
"diagnosis": null, | ||
"symptom": null | ||
}, | ||
{ | ||
"nric": "S9839571A", | ||
"name": "Daniel Meier", | ||
"phone": "87652533", | ||
"address": "10th street", | ||
"dateOfBirth": "2001-01-01", | ||
"sex": "M", | ||
"status": "HEALTHY", | ||
"email": null, | ||
"country": null, | ||
"allergies": null, | ||
"bloodType": null, | ||
"condition": null, | ||
"dateOfAdmission": null, | ||
"diagnosis": null, | ||
"symptom": null | ||
}, | ||
{ | ||
"nric": "S8913957B", | ||
"name": "Elle Meyer", | ||
"phone": "94821224", | ||
"address": "michegan ave", | ||
"dateOfBirth": "2001-01-01", | ||
"sex": "F", | ||
"status": "UNWELL", | ||
"email": null, | ||
"country": null, | ||
"allergies": null, | ||
"bloodType": null, | ||
"condition": null, | ||
"dateOfAdmission": null, | ||
"diagnosis": null, | ||
"symptom": null | ||
}, | ||
{ | ||
"nric": "T0536171Z", | ||
"name": "Fiona Kunz", | ||
"phone": "94820427", | ||
"address": "little tokyo", | ||
"dateOfBirth": "2001-01-01", | ||
"sex": "F", | ||
"status": "PENDING", | ||
"email": null, | ||
"country": null, | ||
"allergies": null, | ||
"bloodType": null, | ||
"condition": null, | ||
"dateOfAdmission": null, | ||
"diagnosis": null, | ||
"symptom": null | ||
}, | ||
{ | ||
"nric": "T0829102Z", | ||
"name": "George Best", | ||
"phone": "94824421", | ||
"address": "4th street", | ||
"dateOfBirth": "2001-01-01", | ||
"sex": "M", | ||
"status": "HEALTHY", | ||
"email": null, | ||
"country": null, | ||
"allergies": null, | ||
"bloodType": null, | ||
"condition": null, | ||
"dateOfAdmission": null, | ||
"diagnosis": null, | ||
"symptom": null | ||
} | ||
] | ||
} |