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.
Merge pull request AY2324S2-CS2103T-T08-1#85 from jovantanyk/fix-storage
Fix storage
- Loading branch information
Showing
24 changed files
with
423 additions
and
313 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
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
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
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
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
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
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
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 | ||
} | ||
] | ||
} |
Oops, something went wrong.