From f50f8265764a4237a560cd39841cbc0d1a6a2ad2 Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Mon, 26 Feb 2024 18:08:26 +0800 Subject: [PATCH 01/16] Remove JsonAdaptedPerson and JsonAdaptedTag --- .../address/storage/JsonAdaptedPerson.java | 109 ----------------- .../seedu/address/storage/JsonAdaptedTag.java | 48 -------- .../storage/JsonAddressBookStorage.java | 2 +- .../storage/JsonSerializableAddressBook.java | 18 ++- .../storage/JsonAdaptedPersonTest.java | 110 ------------------ 5 files changed, 8 insertions(+), 279 deletions(-) delete mode 100644 src/main/java/seedu/address/storage/JsonAdaptedPerson.java delete mode 100644 src/main/java/seedu/address/storage/JsonAdaptedTag.java delete mode 100644 src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java deleted file mode 100644 index bd1ca0f56c8..00000000000 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ /dev/null @@ -1,109 +0,0 @@ -package seedu.address.storage; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.Name; -import seedu.address.model.person.Person; -import seedu.address.model.person.Phone; -import seedu.address.model.tag.Tag; - -/** - * Jackson-friendly version of {@link Person}. - */ -class JsonAdaptedPerson { - - public static final String MISSING_FIELD_MESSAGE_FORMAT = "Person's %s field is missing!"; - - private final String name; - private final String phone; - private final String email; - private final String address; - private final List tags = new ArrayList<>(); - - /** - * Constructs a {@code JsonAdaptedPerson} with the given person details. - */ - @JsonCreator - public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, - @JsonProperty("email") String email, @JsonProperty("address") String address, - @JsonProperty("tags") List tags) { - this.name = name; - this.phone = phone; - this.email = email; - this.address = address; - if (tags != null) { - this.tags.addAll(tags); - } - } - - /** - * Converts a given {@code Person} into this class for Jackson use. - */ - public JsonAdaptedPerson(Person source) { - name = source.getName().fullName; - phone = source.getPhone().value; - email = source.getEmail().value; - address = source.getAddress().value; - tags.addAll(source.getTags().stream() - .map(JsonAdaptedTag::new) - .collect(Collectors.toList())); - } - - /** - * Converts this Jackson-friendly adapted person object into the model's {@code Person} object. - * - * @throws IllegalValueException if there were any data constraints violated in the adapted person. - */ - public Person toModelType() throws IllegalValueException { - final List personTags = new ArrayList<>(); - for (JsonAdaptedTag tag : tags) { - personTags.add(tag.toModelType()); - } - - if (name == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); - } - if (!Name.isValidName(name)) { - throw new IllegalValueException(Name.MESSAGE_CONSTRAINTS); - } - final Name modelName = new Name(name); - - if (phone == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName())); - } - if (!Phone.isValidPhone(phone)) { - throw new IllegalValueException(Phone.MESSAGE_CONSTRAINTS); - } - final Phone modelPhone = new Phone(phone); - - if (email == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName())); - } - if (!Email.isValidEmail(email)) { - throw new IllegalValueException(Email.MESSAGE_CONSTRAINTS); - } - final Email modelEmail = new Email(email); - - if (address == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName())); - } - if (!Address.isValidAddress(address)) { - throw new IllegalValueException(Address.MESSAGE_CONSTRAINTS); - } - final Address modelAddress = new Address(address); - - final Set modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags); - } - -} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedTag.java b/src/main/java/seedu/address/storage/JsonAdaptedTag.java deleted file mode 100644 index 0df22bdb754..00000000000 --- a/src/main/java/seedu/address/storage/JsonAdaptedTag.java +++ /dev/null @@ -1,48 +0,0 @@ -package seedu.address.storage; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.model.tag.Tag; - -/** - * Jackson-friendly version of {@link Tag}. - */ -class JsonAdaptedTag { - - private final String tagName; - - /** - * Constructs a {@code JsonAdaptedTag} with the given {@code tagName}. - */ - @JsonCreator - public JsonAdaptedTag(String tagName) { - this.tagName = tagName; - } - - /** - * Converts a given {@code Tag} into this class for Jackson use. - */ - public JsonAdaptedTag(Tag source) { - tagName = source.tagName; - } - - @JsonValue - public String getTagName() { - return tagName; - } - - /** - * Converts this Jackson-friendly adapted tag object into the model's {@code Tag} object. - * - * @throws IllegalValueException if there were any data constraints violated in the adapted tag. - */ - public Tag toModelType() throws IllegalValueException { - if (!Tag.isValidTagName(tagName)) { - throw new IllegalValueException(Tag.MESSAGE_CONSTRAINTS); - } - return new Tag(tagName); - } - -} diff --git a/src/main/java/seedu/address/storage/JsonAddressBookStorage.java b/src/main/java/seedu/address/storage/JsonAddressBookStorage.java index 41e06f264e1..a326afdbb73 100644 --- a/src/main/java/seedu/address/storage/JsonAddressBookStorage.java +++ b/src/main/java/seedu/address/storage/JsonAddressBookStorage.java @@ -21,7 +21,7 @@ public class JsonAddressBookStorage implements AddressBookStorage { private static final Logger logger = LogsCenter.getLogger(JsonAddressBookStorage.class); - private Path filePath; + private final Path filePath; public JsonAddressBookStorage(Path filePath) { this.filePath = filePath; diff --git a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java index 5efd834091d..2848c6770e8 100644 --- a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java +++ b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java @@ -2,10 +2,7 @@ import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; import seedu.address.commons.exceptions.IllegalValueException; @@ -21,15 +18,15 @@ class JsonSerializableAddressBook { public static final String MESSAGE_DUPLICATE_PERSON = "Persons list contains duplicate person(s)."; - private final List persons = new ArrayList<>(); + private final List persons = new ArrayList<>(); /** * Constructs a {@code JsonSerializableAddressBook} with the given persons. */ - @JsonCreator - public JsonSerializableAddressBook(@JsonProperty("persons") List persons) { - this.persons.addAll(persons); - } +// @JsonCreator +// public JsonSerializableAddressBook(@JsonProperty("persons") List persons) { +// this.persons.addAll(persons); +// } /** * Converts a given {@code ReadOnlyAddressBook} into this class for Jackson use. @@ -37,7 +34,7 @@ public JsonSerializableAddressBook(@JsonProperty("persons") List VALID_TAGS = BENSON.getTags().stream() - .map(JsonAdaptedTag::new) - .collect(Collectors.toList()); - - @Test - public void toModelType_validPersonDetails_returnsPerson() throws Exception { - JsonAdaptedPerson person = new JsonAdaptedPerson(BENSON); - assertEquals(BENSON, person.toModelType()); - } - - @Test - public void toModelType_invalidName_throwsIllegalValueException() { - JsonAdaptedPerson person = - new JsonAdaptedPerson(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS); - String expectedMessage = Name.MESSAGE_CONSTRAINTS; - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); - } - - @Test - public void toModelType_nullName_throwsIllegalValueException() { - JsonAdaptedPerson person = new JsonAdaptedPerson(null, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS); - String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()); - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); - } - - @Test - public void toModelType_invalidPhone_throwsIllegalValueException() { - JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS); - String expectedMessage = Phone.MESSAGE_CONSTRAINTS; - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); - } - - @Test - public void toModelType_nullPhone_throwsIllegalValueException() { - JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, null, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS); - String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName()); - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); - } - - @Test - public void toModelType_invalidEmail_throwsIllegalValueException() { - JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_ADDRESS, VALID_TAGS); - String expectedMessage = Email.MESSAGE_CONSTRAINTS; - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); - } - - @Test - public void toModelType_nullEmail_throwsIllegalValueException() { - JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, null, VALID_ADDRESS, VALID_TAGS); - String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName()); - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); - } - - @Test - public void toModelType_invalidAddress_throwsIllegalValueException() { - JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS, VALID_TAGS); - String expectedMessage = Address.MESSAGE_CONSTRAINTS; - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); - } - - @Test - public void toModelType_nullAddress_throwsIllegalValueException() { - JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, null, VALID_TAGS); - String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName()); - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); - } - - @Test - public void toModelType_invalidTags_throwsIllegalValueException() { - List invalidTags = new ArrayList<>(VALID_TAGS); - invalidTags.add(new JsonAdaptedTag(INVALID_TAG)); - JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, invalidTags); - assertThrows(IllegalValueException.class, person::toModelType); - } - -} From 5cf15e318fbc4f8362dfd4d0305070c082e59f9d Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Mon, 26 Feb 2024 18:39:40 +0800 Subject: [PATCH 02/16] Move Json annotations into Person and Tag --- .../seedu/address/commons/util/JsonUtil.java | 15 +-------------- .../java/seedu/address/model/person/Person.java | 17 +++++++++++++++++ src/main/java/seedu/address/model/tag/Tag.java | 9 +++++++++ .../storage/JsonSerializableAddressBook.java | 8 -------- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/main/java/seedu/address/commons/util/JsonUtil.java b/src/main/java/seedu/address/commons/util/JsonUtil.java index 100cb16c395..11eca5d080b 100644 --- a/src/main/java/seedu/address/commons/util/JsonUtil.java +++ b/src/main/java/seedu/address/commons/util/JsonUtil.java @@ -9,16 +9,10 @@ import java.util.logging.Level; import java.util.logging.Logger; -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.deser.std.FromStringDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import seedu.address.commons.core.LogsCenter; import seedu.address.commons.exceptions.DataLoadingException; @@ -30,14 +24,7 @@ public class JsonUtil { private static final Logger logger = LogsCenter.getLogger(JsonUtil.class); - private static ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules() - .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) - .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE) - .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY) - .registerModule(new SimpleModule("SimpleModule") - .addSerializer(Level.class, new ToStringSerializer()) - .addDeserializer(Level.class, new LevelDeserializer(Level.class))); + private static final ObjectMapper objectMapper = new ObjectMapper(); static void serializeObjectToJsonFile(Path jsonFile, T objectToSerialize) throws IOException { FileUtil.writeToFile(jsonFile, toJsonString(objectToSerialize)); diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index abe8c46b535..c2107999706 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -4,9 +4,13 @@ import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Objects; import java.util.Set; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + import seedu.address.commons.util.ToStringBuilder; import seedu.address.model.tag.Tag; @@ -37,6 +41,19 @@ public Person(Name name, Phone phone, Email email, Address address, Set tag this.tags.addAll(tags); } + @JsonCreator + public Person(@JsonProperty("name") String name, @JsonProperty("phone") String phone, + @JsonProperty("email") String email, @JsonProperty("address") String address, + @JsonProperty("tags") List tags) { + this.name = new Name(name); + this.phone = new Phone(phone); + this.email = new Email(email); + this.address = new Address(address); + if (tags != null) { + this.tags.addAll(tags); + } + } + public Name getName() { return name; } diff --git a/src/main/java/seedu/address/model/tag/Tag.java b/src/main/java/seedu/address/model/tag/Tag.java index f1a0d4e233b..2d9bb05df28 100644 --- a/src/main/java/seedu/address/model/tag/Tag.java +++ b/src/main/java/seedu/address/model/tag/Tag.java @@ -3,6 +3,9 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + /** * Represents a Tag in the address book. * Guarantees: immutable; name is valid as declared in {@link #isValidTagName(String)} @@ -19,12 +22,18 @@ public class Tag { * * @param tagName A valid tag name. */ + @JsonCreator public Tag(String tagName) { requireNonNull(tagName); checkArgument(isValidTagName(tagName), MESSAGE_CONSTRAINTS); this.tagName = tagName; } + @JsonValue + public String getTagName() { + return tagName; + } + /** * Returns true if a given string is a valid tag name. */ diff --git a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java index 2848c6770e8..348113e22ed 100644 --- a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java +++ b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java @@ -20,14 +20,6 @@ class JsonSerializableAddressBook { private final List persons = new ArrayList<>(); - /** - * Constructs a {@code JsonSerializableAddressBook} with the given persons. - */ -// @JsonCreator -// public JsonSerializableAddressBook(@JsonProperty("persons") List persons) { -// this.persons.addAll(persons); -// } - /** * Converts a given {@code ReadOnlyAddressBook} into this class for Jackson use. * From 2eeeb964416924bf0f9a7df3216bc6140f2b9cf9 Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Mon, 26 Feb 2024 18:48:56 +0800 Subject: [PATCH 03/16] Revert ObjectMapper changes --- .../java/seedu/address/commons/util/JsonUtil.java | 15 ++++++++++++++- .../storage/JsonSerializableAddressBook.java | 10 ++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/commons/util/JsonUtil.java b/src/main/java/seedu/address/commons/util/JsonUtil.java index 11eca5d080b..eaa785f85c7 100644 --- a/src/main/java/seedu/address/commons/util/JsonUtil.java +++ b/src/main/java/seedu/address/commons/util/JsonUtil.java @@ -9,10 +9,16 @@ import java.util.logging.Level; import java.util.logging.Logger; +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.deser.std.FromStringDeserializer; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import seedu.address.commons.core.LogsCenter; import seedu.address.commons.exceptions.DataLoadingException; @@ -24,7 +30,14 @@ public class JsonUtil { private static final Logger logger = LogsCenter.getLogger(JsonUtil.class); - private static final ObjectMapper objectMapper = new ObjectMapper(); + private static final ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules() + .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE) + .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY) + .registerModule(new SimpleModule("SimpleModule") + .addSerializer(Level.class, new ToStringSerializer()) + .addDeserializer(Level.class, new LevelDeserializer(Level.class))); static void serializeObjectToJsonFile(Path jsonFile, T objectToSerialize) throws IOException { FileUtil.writeToFile(jsonFile, toJsonString(objectToSerialize)); diff --git a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java index 348113e22ed..6e16069367d 100644 --- a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java +++ b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; import seedu.address.commons.exceptions.IllegalValueException; @@ -20,6 +22,14 @@ class JsonSerializableAddressBook { private final List persons = new ArrayList<>(); + /** + * Constructs a {@code JsonSerializableAddressBook} with the given persons. + */ + @JsonCreator + public JsonSerializableAddressBook(@JsonProperty("persons") List persons) { + this.persons.addAll(persons); + } + /** * Converts a given {@code ReadOnlyAddressBook} into this class for Jackson use. * From cd6d7fa261ad6227f6f67a612d77290f442ea665 Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Mon, 26 Feb 2024 18:57:05 +0800 Subject: [PATCH 04/16] Fix JsonSerializableAddressBookTest --- .../address/storage/JsonSerializableAddressBookTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java index 188c9058d20..504a71e701c 100644 --- a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java +++ b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test; +import seedu.address.commons.exceptions.DataLoadingException; import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.commons.util.JsonUtil; import seedu.address.model.AddressBook; @@ -30,10 +31,9 @@ public void toModelType_typicalPersonsFile_success() throws Exception { } @Test - public void toModelType_invalidPersonFile_throwsIllegalValueException() throws Exception { - JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(INVALID_PERSON_FILE, - JsonSerializableAddressBook.class).get(); - assertThrows(IllegalValueException.class, dataFromFile::toModelType); + public void toModelType_invalidPersonFile_throwsDataLoadingException() { + assertThrows(DataLoadingException.class, () -> JsonUtil.readJsonFile(INVALID_PERSON_FILE, + JsonSerializableAddressBook.class)); } @Test From a6de5b5404adc81bb9300dd5bc483fce6b4b9774 Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Mon, 26 Feb 2024 19:12:48 +0800 Subject: [PATCH 05/16] Make AddressBook serializable --- .../java/seedu/address/model/AddressBook.java | 10 ++++++++++ .../address/storage/JsonAddressBookStorage.java | 17 +++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index 73397161e84..56ce0a40d91 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -4,6 +4,10 @@ import java.util.List; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; + import javafx.collections.ObservableList; import seedu.address.commons.util.ToStringBuilder; import seedu.address.model.person.Person; @@ -13,6 +17,7 @@ * Wraps all data at the address-book level * Duplicates are not allowed (by .isSamePerson comparison) */ +@JsonRootName(value = "addressbook") public class AddressBook implements ReadOnlyAddressBook { private final UniquePersonList persons; @@ -30,6 +35,11 @@ public class AddressBook implements ReadOnlyAddressBook { public AddressBook() {} + @JsonCreator + public AddressBook(@JsonProperty("persons") List persons) { + this.persons.setPersons(persons); + } + /** * Creates an AddressBook using the Persons in the {@code toBeCopied} */ diff --git a/src/main/java/seedu/address/storage/JsonAddressBookStorage.java b/src/main/java/seedu/address/storage/JsonAddressBookStorage.java index a326afdbb73..66479821610 100644 --- a/src/main/java/seedu/address/storage/JsonAddressBookStorage.java +++ b/src/main/java/seedu/address/storage/JsonAddressBookStorage.java @@ -9,9 +9,9 @@ import seedu.address.commons.core.LogsCenter; import seedu.address.commons.exceptions.DataLoadingException; -import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.commons.util.FileUtil; import seedu.address.commons.util.JsonUtil; +import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; /** @@ -45,18 +45,11 @@ public Optional readAddressBook() throws DataLoadingExcepti public Optional readAddressBook(Path filePath) throws DataLoadingException { requireNonNull(filePath); - Optional jsonAddressBook = JsonUtil.readJsonFile( - filePath, JsonSerializableAddressBook.class); - if (!jsonAddressBook.isPresent()) { + Optional addressBook = JsonUtil.readJsonFile(filePath, AddressBook.class); + if (!addressBook.isPresent()) { return Optional.empty(); } - - try { - return Optional.of(jsonAddressBook.get().toModelType()); - } catch (IllegalValueException ive) { - logger.info("Illegal values found in " + filePath + ": " + ive.getMessage()); - throw new DataLoadingException(ive); - } + return Optional.of(addressBook.get()); } @Override @@ -74,7 +67,7 @@ public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) thro requireNonNull(filePath); FileUtil.createIfMissing(filePath); - JsonUtil.saveJsonFile(new JsonSerializableAddressBook(addressBook), filePath); + JsonUtil.saveJsonFile(addressBook, filePath); } } From a69b4621c80562939abf380a5b899d028a44668c Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:00:22 +0800 Subject: [PATCH 06/16] Add JsonValue notations --- .../java/seedu/address/model/AddressBook.java | 2 +- .../java/seedu/address/model/person/Address.java | 12 +++++++++++- .../java/seedu/address/model/person/Email.java | 12 +++++++++++- .../java/seedu/address/model/person/Name.java | 12 +++++++++++- .../java/seedu/address/model/person/Person.java | 16 +--------------- .../java/seedu/address/model/person/Phone.java | 12 +++++++++++- .../address/model/person/UniquePersonList.java | 3 +++ 7 files changed, 49 insertions(+), 20 deletions(-) diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index 56ce0a40d91..822a2f8bb1e 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -17,7 +17,7 @@ * Wraps all data at the address-book level * Duplicates are not allowed (by .isSamePerson comparison) */ -@JsonRootName(value = "addressbook") +@JsonRootName("addressbook") public class AddressBook implements ReadOnlyAddressBook { private final UniquePersonList persons; diff --git a/src/main/java/seedu/address/model/person/Address.java b/src/main/java/seedu/address/model/person/Address.java index 469a2cc9a1e..17c917a206a 100644 --- a/src/main/java/seedu/address/model/person/Address.java +++ b/src/main/java/seedu/address/model/person/Address.java @@ -3,6 +3,10 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; + /** * Represents a Person's address in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidAddress(String)} @@ -24,12 +28,18 @@ public class Address { * * @param address A valid address. */ - public Address(String address) { + @JsonCreator + public Address(@JsonProperty String address) { requireNonNull(address); checkArgument(isValidAddress(address), MESSAGE_CONSTRAINTS); value = address; } + @JsonValue + public String get() { + return value; + } + /** * Returns true if a given string is a valid email. */ diff --git a/src/main/java/seedu/address/model/person/Email.java b/src/main/java/seedu/address/model/person/Email.java index c62e512bc29..37d8b8becd6 100644 --- a/src/main/java/seedu/address/model/person/Email.java +++ b/src/main/java/seedu/address/model/person/Email.java @@ -3,6 +3,10 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; + /** * Represents a Person's email in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidEmail(String)} @@ -38,12 +42,18 @@ public class Email { * * @param email A valid email address. */ - public Email(String email) { + @JsonCreator + public Email(@JsonProperty String email) { requireNonNull(email); checkArgument(isValidEmail(email), MESSAGE_CONSTRAINTS); value = email; } + @JsonValue + public String get() { + return value; + } + /** * Returns if a given string is a valid email. */ diff --git a/src/main/java/seedu/address/model/person/Name.java b/src/main/java/seedu/address/model/person/Name.java index 173f15b9b00..1f097f825ac 100644 --- a/src/main/java/seedu/address/model/person/Name.java +++ b/src/main/java/seedu/address/model/person/Name.java @@ -3,6 +3,10 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; + /** * Represents a Person's name in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidName(String)} @@ -25,12 +29,18 @@ public class Name { * * @param name A valid name. */ - public Name(String name) { + @JsonCreator + public Name(@JsonProperty String name) { requireNonNull(name); checkArgument(isValidName(name), MESSAGE_CONSTRAINTS); fullName = name; } + @JsonValue + public String get() { + return fullName; + } + /** * Returns true if a given string is a valid name. */ diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index c2107999706..a4f0cc86c5e 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -4,12 +4,10 @@ import java.util.Collections; import java.util.HashSet; -import java.util.List; import java.util.Objects; import java.util.Set; import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import seedu.address.commons.util.ToStringBuilder; import seedu.address.model.tag.Tag; @@ -32,6 +30,7 @@ public class Person { /** * Every field must be present and not null. */ + @JsonCreator public Person(Name name, Phone phone, Email email, Address address, Set tags) { requireAllNonNull(name, phone, email, address, tags); this.name = name; @@ -41,19 +40,6 @@ public Person(Name name, Phone phone, Email email, Address address, Set tag this.tags.addAll(tags); } - @JsonCreator - public Person(@JsonProperty("name") String name, @JsonProperty("phone") String phone, - @JsonProperty("email") String email, @JsonProperty("address") String address, - @JsonProperty("tags") List tags) { - this.name = new Name(name); - this.phone = new Phone(phone); - this.email = new Email(email); - this.address = new Address(address); - if (tags != null) { - this.tags.addAll(tags); - } - } - public Name getName() { return name; } diff --git a/src/main/java/seedu/address/model/person/Phone.java b/src/main/java/seedu/address/model/person/Phone.java index d733f63d739..c852382cf94 100644 --- a/src/main/java/seedu/address/model/person/Phone.java +++ b/src/main/java/seedu/address/model/person/Phone.java @@ -3,6 +3,10 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; + /** * Represents a Person's phone number in the address book. * Guarantees: immutable; is valid as declared in {@link #isValidPhone(String)} @@ -20,12 +24,18 @@ public class Phone { * * @param phone A valid phone number. */ - public Phone(String phone) { + @JsonCreator + public Phone(@JsonProperty("phone") String phone) { requireNonNull(phone); checkArgument(isValidPhone(phone), MESSAGE_CONSTRAINTS); value = phone; } + @JsonValue + public String get() { + return value; + } + /** * Returns true if a given string is a valid phone number. */ diff --git a/src/main/java/seedu/address/model/person/UniquePersonList.java b/src/main/java/seedu/address/model/person/UniquePersonList.java index cc0a68d79f9..5b3b181cbc7 100644 --- a/src/main/java/seedu/address/model/person/UniquePersonList.java +++ b/src/main/java/seedu/address/model/person/UniquePersonList.java @@ -6,6 +6,8 @@ import java.util.Iterator; import java.util.List; +import com.fasterxml.jackson.annotation.JsonValue; + import javafx.collections.FXCollections; import javafx.collections.ObservableList; import seedu.address.model.person.exceptions.DuplicatePersonException; @@ -100,6 +102,7 @@ public void setPersons(List persons) { /** * Returns the backing list as an unmodifiable {@code ObservableList}. */ + @JsonValue public ObservableList asUnmodifiableObservableList() { return internalUnmodifiableList; } From 3670249bee606c37c8a150ed8c5095a46300548d Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:01:24 +0800 Subject: [PATCH 07/16] Remove JsonSerializableAddressBook --- .../storage/JsonSerializableAddressBook.java | 58 ------------------- .../JsonSerializableAddressBookTest.java | 47 --------------- 2 files changed, 105 deletions(-) delete mode 100644 src/main/java/seedu/address/storage/JsonSerializableAddressBook.java delete mode 100644 src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java diff --git a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java deleted file mode 100644 index 6e16069367d..00000000000 --- a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java +++ /dev/null @@ -1,58 +0,0 @@ -package seedu.address.storage; - -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonRootName; - -import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.model.AddressBook; -import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.person.Person; - -/** - * An Immutable AddressBook that is serializable to JSON format. - */ -@JsonRootName(value = "addressbook") -class JsonSerializableAddressBook { - - public static final String MESSAGE_DUPLICATE_PERSON = "Persons list contains duplicate person(s)."; - - private final List persons = new ArrayList<>(); - - /** - * Constructs a {@code JsonSerializableAddressBook} with the given persons. - */ - @JsonCreator - public JsonSerializableAddressBook(@JsonProperty("persons") List persons) { - this.persons.addAll(persons); - } - - /** - * Converts a given {@code ReadOnlyAddressBook} into this class for Jackson use. - * - * @param source future changes to this will not affect the created {@code JsonSerializableAddressBook}. - */ - public JsonSerializableAddressBook(ReadOnlyAddressBook source) { - persons.addAll(source.getPersonList()); - } - - /** - * Converts this address book into the model's {@code AddressBook} object. - * - * @throws IllegalValueException if there were any data constraints violated. - */ - public AddressBook toModelType() throws IllegalValueException { - AddressBook addressBook = new AddressBook(); - for (Person person : persons) { - if (addressBook.hasPerson(person)) { - throw new IllegalValueException(MESSAGE_DUPLICATE_PERSON); - } - addressBook.addPerson(person); - } - return addressBook; - } - -} diff --git a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java deleted file mode 100644 index 504a71e701c..00000000000 --- a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package seedu.address.storage; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static seedu.address.testutil.Assert.assertThrows; - -import java.nio.file.Path; -import java.nio.file.Paths; - -import org.junit.jupiter.api.Test; - -import seedu.address.commons.exceptions.DataLoadingException; -import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.commons.util.JsonUtil; -import seedu.address.model.AddressBook; -import seedu.address.testutil.TypicalPersons; - -public class JsonSerializableAddressBookTest { - - private static final Path TEST_DATA_FOLDER = Paths.get("src", "test", "data", "JsonSerializableAddressBookTest"); - private static final Path TYPICAL_PERSONS_FILE = TEST_DATA_FOLDER.resolve("typicalPersonsAddressBook.json"); - private static final Path INVALID_PERSON_FILE = TEST_DATA_FOLDER.resolve("invalidPersonAddressBook.json"); - private static final Path DUPLICATE_PERSON_FILE = TEST_DATA_FOLDER.resolve("duplicatePersonAddressBook.json"); - - @Test - public void toModelType_typicalPersonsFile_success() throws Exception { - JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(TYPICAL_PERSONS_FILE, - JsonSerializableAddressBook.class).get(); - AddressBook addressBookFromFile = dataFromFile.toModelType(); - AddressBook typicalPersonsAddressBook = TypicalPersons.getTypicalAddressBook(); - assertEquals(addressBookFromFile, typicalPersonsAddressBook); - } - - @Test - public void toModelType_invalidPersonFile_throwsDataLoadingException() { - assertThrows(DataLoadingException.class, () -> JsonUtil.readJsonFile(INVALID_PERSON_FILE, - JsonSerializableAddressBook.class)); - } - - @Test - public void toModelType_duplicatePersons_throwsIllegalValueException() throws Exception { - JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(DUPLICATE_PERSON_FILE, - JsonSerializableAddressBook.class).get(); - assertThrows(IllegalValueException.class, JsonSerializableAddressBook.MESSAGE_DUPLICATE_PERSON, - dataFromFile::toModelType); - } - -} From 1da3353380d9649b2d00f714e7482dffe45ed587 Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:38:36 +0800 Subject: [PATCH 08/16] Remove unnecessary annotations --- src/main/java/seedu/address/model/AddressBook.java | 10 ---------- src/main/java/seedu/address/model/person/Person.java | 3 --- src/main/java/seedu/address/model/person/Phone.java | 2 +- .../seedu/address/model/person/UniquePersonList.java | 2 ++ src/main/java/seedu/address/model/tag/Tag.java | 4 +--- 5 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index 822a2f8bb1e..73397161e84 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -4,10 +4,6 @@ import java.util.List; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonRootName; - import javafx.collections.ObservableList; import seedu.address.commons.util.ToStringBuilder; import seedu.address.model.person.Person; @@ -17,7 +13,6 @@ * Wraps all data at the address-book level * Duplicates are not allowed (by .isSamePerson comparison) */ -@JsonRootName("addressbook") public class AddressBook implements ReadOnlyAddressBook { private final UniquePersonList persons; @@ -35,11 +30,6 @@ public class AddressBook implements ReadOnlyAddressBook { public AddressBook() {} - @JsonCreator - public AddressBook(@JsonProperty("persons") List persons) { - this.persons.setPersons(persons); - } - /** * Creates an AddressBook using the Persons in the {@code toBeCopied} */ diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index a4f0cc86c5e..abe8c46b535 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -7,8 +7,6 @@ import java.util.Objects; import java.util.Set; -import com.fasterxml.jackson.annotation.JsonCreator; - import seedu.address.commons.util.ToStringBuilder; import seedu.address.model.tag.Tag; @@ -30,7 +28,6 @@ public class Person { /** * Every field must be present and not null. */ - @JsonCreator public Person(Name name, Phone phone, Email email, Address address, Set tags) { requireAllNonNull(name, phone, email, address, tags); this.name = name; diff --git a/src/main/java/seedu/address/model/person/Phone.java b/src/main/java/seedu/address/model/person/Phone.java index c852382cf94..f93bea7cfe8 100644 --- a/src/main/java/seedu/address/model/person/Phone.java +++ b/src/main/java/seedu/address/model/person/Phone.java @@ -25,7 +25,7 @@ public class Phone { * @param phone A valid phone number. */ @JsonCreator - public Phone(@JsonProperty("phone") String phone) { + public Phone(@JsonProperty String phone) { requireNonNull(phone); checkArgument(isValidPhone(phone), MESSAGE_CONSTRAINTS); value = phone; diff --git a/src/main/java/seedu/address/model/person/UniquePersonList.java b/src/main/java/seedu/address/model/person/UniquePersonList.java index 5b3b181cbc7..31c0c032854 100644 --- a/src/main/java/seedu/address/model/person/UniquePersonList.java +++ b/src/main/java/seedu/address/model/person/UniquePersonList.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.List; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import javafx.collections.FXCollections; @@ -90,6 +91,7 @@ public void setPersons(UniquePersonList replacement) { * Replaces the contents of this list with {@code persons}. * {@code persons} must not contain duplicate persons. */ + @JsonCreator public void setPersons(List persons) { requireAllNonNull(persons); if (!personsAreUnique(persons)) { diff --git a/src/main/java/seedu/address/model/tag/Tag.java b/src/main/java/seedu/address/model/tag/Tag.java index 2d9bb05df28..b998982bc71 100644 --- a/src/main/java/seedu/address/model/tag/Tag.java +++ b/src/main/java/seedu/address/model/tag/Tag.java @@ -3,7 +3,6 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; -import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; /** @@ -22,7 +21,6 @@ public class Tag { * * @param tagName A valid tag name. */ - @JsonCreator public Tag(String tagName) { requireNonNull(tagName); checkArgument(isValidTagName(tagName), MESSAGE_CONSTRAINTS); @@ -30,7 +28,7 @@ public Tag(String tagName) { } @JsonValue - public String getTagName() { + public String get() { return tagName; } From 711f3460ddcf56d80ab5a29a49cc6be300d46c24 Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Tue, 27 Feb 2024 01:18:42 +0800 Subject: [PATCH 09/16] Add custom deserializer for UniquePersonList --- .../seedu/address/commons/util/JsonUtil.java | 2 +- .../seedu/address/model/person/Person.java | 18 ++++++++++ .../model/person/UniquePersonList.java | 7 ++-- .../storage/UniquePersonListDeserializer.java | 34 +++++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/main/java/seedu/address/storage/UniquePersonListDeserializer.java diff --git a/src/main/java/seedu/address/commons/util/JsonUtil.java b/src/main/java/seedu/address/commons/util/JsonUtil.java index eaa785f85c7..1aa5825fe86 100644 --- a/src/main/java/seedu/address/commons/util/JsonUtil.java +++ b/src/main/java/seedu/address/commons/util/JsonUtil.java @@ -35,7 +35,7 @@ public class JsonUtil { .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE) .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY) - .registerModule(new SimpleModule("SimpleModule") + .registerModule(new SimpleModule("Logger") .addSerializer(Level.class, new ToStringSerializer()) .addDeserializer(Level.class, new LevelDeserializer(Level.class))); diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index abe8c46b535..fc20c5f0bfa 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -4,9 +4,13 @@ import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Objects; import java.util.Set; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + import seedu.address.commons.util.ToStringBuilder; import seedu.address.model.tag.Tag; @@ -37,6 +41,20 @@ public Person(Name name, Phone phone, Email email, Address address, Set tag this.tags.addAll(tags); } + @JsonCreator + private Person(@JsonProperty("name") String name, @JsonProperty("phone") String phone, + @JsonProperty("email") String email, @JsonProperty("address") String address, + @JsonProperty("tags") List tagNames) { + requireAllNonNull(name, phone, email, address, tagNames); + this.name = new Name(name); + this.phone = new Phone(phone); + this.email = new Email(email); + this.address = new Address(address); + for (String tagName : tagNames) { + this.tags.add(new Tag(tagName)); + } + } + public Name getName() { return name; } diff --git a/src/main/java/seedu/address/model/person/UniquePersonList.java b/src/main/java/seedu/address/model/person/UniquePersonList.java index 31c0c032854..aadc40710bd 100644 --- a/src/main/java/seedu/address/model/person/UniquePersonList.java +++ b/src/main/java/seedu/address/model/person/UniquePersonList.java @@ -6,13 +6,15 @@ import java.util.Iterator; import java.util.List; -import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import seedu.address.model.person.exceptions.DuplicatePersonException; import seedu.address.model.person.exceptions.PersonNotFoundException; +import seedu.address.storage.UniquePersonListDeserializer; /** * A list of persons that enforces uniqueness between its elements and does not allow nulls. @@ -25,6 +27,7 @@ * * @see Person#isSamePerson(Person) */ +@JsonDeserialize(using = UniquePersonListDeserializer.class) public class UniquePersonList implements Iterable { private final ObservableList internalList = FXCollections.observableArrayList(); @@ -91,7 +94,7 @@ public void setPersons(UniquePersonList replacement) { * Replaces the contents of this list with {@code persons}. * {@code persons} must not contain duplicate persons. */ - @JsonCreator + @JsonSetter public void setPersons(List persons) { requireAllNonNull(persons); if (!personsAreUnique(persons)) { diff --git a/src/main/java/seedu/address/storage/UniquePersonListDeserializer.java b/src/main/java/seedu/address/storage/UniquePersonListDeserializer.java new file mode 100644 index 00000000000..53fc772a298 --- /dev/null +++ b/src/main/java/seedu/address/storage/UniquePersonListDeserializer.java @@ -0,0 +1,34 @@ +package seedu.address.storage; + +import java.io.IOException; +import java.util.List; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; + +import seedu.address.model.person.Person; +import seedu.address.model.person.UniquePersonList; + +public class UniquePersonListDeserializer extends StdDeserializer { + + public UniquePersonListDeserializer() { + this(null); + } + + public UniquePersonListDeserializer(Class vc) { + super(vc); + } + + @Override + public UniquePersonList deserialize(JsonParser parser, + DeserializationContext context) throws IOException, JsonProcessingException { + List persons = context.readValue(parser, + context.getTypeFactory().constructCollectionType(List.class, Person.class)); + UniquePersonList upl = new UniquePersonList(); + upl.setPersons(persons); + return upl; + } + +} From 39665b57f1a551d894a56dcf246187d1785ba208 Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Tue, 27 Feb 2024 01:46:05 +0800 Subject: [PATCH 10/16] Cleanup and fix checkstyle --- .../java/seedu/address/model/person/UniquePersonList.java | 4 +--- .../seedu/address/storage/UniquePersonListDeserializer.java | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/model/person/UniquePersonList.java b/src/main/java/seedu/address/model/person/UniquePersonList.java index aadc40710bd..8f2b329872e 100644 --- a/src/main/java/seedu/address/model/person/UniquePersonList.java +++ b/src/main/java/seedu/address/model/person/UniquePersonList.java @@ -31,8 +31,6 @@ public class UniquePersonList implements Iterable { private final ObservableList internalList = FXCollections.observableArrayList(); - private final ObservableList internalUnmodifiableList = - FXCollections.unmodifiableObservableList(internalList); /** * Returns true if the list contains an equivalent person as the given argument. @@ -109,7 +107,7 @@ public void setPersons(List persons) { */ @JsonValue public ObservableList asUnmodifiableObservableList() { - return internalUnmodifiableList; + return FXCollections.unmodifiableObservableList(internalList); } @Override diff --git a/src/main/java/seedu/address/storage/UniquePersonListDeserializer.java b/src/main/java/seedu/address/storage/UniquePersonListDeserializer.java index 53fc772a298..e8a04a28247 100644 --- a/src/main/java/seedu/address/storage/UniquePersonListDeserializer.java +++ b/src/main/java/seedu/address/storage/UniquePersonListDeserializer.java @@ -11,6 +11,10 @@ import seedu.address.model.person.Person; import seedu.address.model.person.UniquePersonList; +/** + * Implements a custom deserializer for UniquePersonList, + * as Jackson does not support JavaFX collections. + */ public class UniquePersonListDeserializer extends StdDeserializer { public UniquePersonListDeserializer() { From ffc7ed0bd22ec4499e48bfcb88e2a831aa50d412 Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Tue, 27 Feb 2024 01:58:04 +0800 Subject: [PATCH 11/16] Refactor variable names --- .../seedu/address/model/person/Address.java | 19 ++++++++----------- .../seedu/address/model/person/Email.java | 19 ++++++++----------- .../java/seedu/address/model/person/Name.java | 19 ++++++++----------- .../person/NameContainsKeywordsPredicate.java | 2 +- .../seedu/address/model/person/Phone.java | 12 ++++++------ .../java/seedu/address/ui/PersonCard.java | 8 ++++---- .../logic/commands/CommandTestUtil.java | 2 +- .../seedu/address/model/ModelManagerTest.java | 2 +- .../seedu/address/testutil/PersonUtil.java | 16 ++++++++-------- 9 files changed, 45 insertions(+), 54 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Address.java b/src/main/java/seedu/address/model/person/Address.java index 17c917a206a..18e902f5cdd 100644 --- a/src/main/java/seedu/address/model/person/Address.java +++ b/src/main/java/seedu/address/model/person/Address.java @@ -3,8 +3,6 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; /** @@ -21,23 +19,22 @@ public class Address { */ public static final String VALIDATION_REGEX = "[^\\s].*"; - public final String value; + public final String address; /** * Constructs an {@code Address}. * * @param address A valid address. */ - @JsonCreator - public Address(@JsonProperty String address) { + public Address(String address) { requireNonNull(address); checkArgument(isValidAddress(address), MESSAGE_CONSTRAINTS); - value = address; + this.address = address; } @JsonValue - public String get() { - return value; + private String get() { + return address; } /** @@ -49,7 +46,7 @@ public static boolean isValidAddress(String test) { @Override public String toString() { - return value; + return address; } @Override @@ -64,12 +61,12 @@ public boolean equals(Object other) { } Address otherAddress = (Address) other; - return value.equals(otherAddress.value); + return address.equals(otherAddress.address); } @Override public int hashCode() { - return value.hashCode(); + return address.hashCode(); } } diff --git a/src/main/java/seedu/address/model/person/Email.java b/src/main/java/seedu/address/model/person/Email.java index 37d8b8becd6..53e5d3b6428 100644 --- a/src/main/java/seedu/address/model/person/Email.java +++ b/src/main/java/seedu/address/model/person/Email.java @@ -3,8 +3,6 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; /** @@ -35,23 +33,22 @@ public class Email { private static final String DOMAIN_REGEX = "(" + DOMAIN_PART_REGEX + "\\.)*" + DOMAIN_LAST_PART_REGEX; public static final String VALIDATION_REGEX = LOCAL_PART_REGEX + "@" + DOMAIN_REGEX; - public final String value; + public final String email; /** * Constructs an {@code Email}. * * @param email A valid email address. */ - @JsonCreator - public Email(@JsonProperty String email) { + public Email(String email) { requireNonNull(email); checkArgument(isValidEmail(email), MESSAGE_CONSTRAINTS); - value = email; + this.email = email; } @JsonValue - public String get() { - return value; + private String get() { + return email; } /** @@ -63,7 +60,7 @@ public static boolean isValidEmail(String test) { @Override public String toString() { - return value; + return email; } @Override @@ -78,12 +75,12 @@ public boolean equals(Object other) { } Email otherEmail = (Email) other; - return value.equals(otherEmail.value); + return email.equals(otherEmail.email); } @Override public int hashCode() { - return value.hashCode(); + return email.hashCode(); } } diff --git a/src/main/java/seedu/address/model/person/Name.java b/src/main/java/seedu/address/model/person/Name.java index 1f097f825ac..827856fccbb 100644 --- a/src/main/java/seedu/address/model/person/Name.java +++ b/src/main/java/seedu/address/model/person/Name.java @@ -3,8 +3,6 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; /** @@ -22,23 +20,22 @@ public class Name { */ public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; - public final String fullName; + public final String name; /** * Constructs a {@code Name}. * * @param name A valid name. */ - @JsonCreator - public Name(@JsonProperty String name) { + public Name(String name) { requireNonNull(name); checkArgument(isValidName(name), MESSAGE_CONSTRAINTS); - fullName = name; + this.name = name; } @JsonValue - public String get() { - return fullName; + private String get() { + return name; } /** @@ -51,7 +48,7 @@ public static boolean isValidName(String test) { @Override public String toString() { - return fullName; + return name; } @Override @@ -66,12 +63,12 @@ public boolean equals(Object other) { } Name otherName = (Name) other; - return fullName.equals(otherName.fullName); + return name.equals(otherName.name); } @Override public int hashCode() { - return fullName.hashCode(); + return name.hashCode(); } } diff --git a/src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java index 62d19be2977..aa43e33f9a0 100644 --- a/src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java +++ b/src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java @@ -19,7 +19,7 @@ public NameContainsKeywordsPredicate(List keywords) { @Override public boolean test(Person person) { return keywords.stream() - .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(person.getName().fullName, keyword)); + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(person.getName().name, keyword)); } @Override diff --git a/src/main/java/seedu/address/model/person/Phone.java b/src/main/java/seedu/address/model/person/Phone.java index f93bea7cfe8..94e8abdb207 100644 --- a/src/main/java/seedu/address/model/person/Phone.java +++ b/src/main/java/seedu/address/model/person/Phone.java @@ -17,7 +17,7 @@ public class Phone { public static final String MESSAGE_CONSTRAINTS = "Phone numbers should only contain numbers, and it should be at least 3 digits long"; public static final String VALIDATION_REGEX = "\\d{3,}"; - public final String value; + public final String phone; /** * Constructs a {@code Phone}. @@ -28,12 +28,12 @@ public class Phone { public Phone(@JsonProperty String phone) { requireNonNull(phone); checkArgument(isValidPhone(phone), MESSAGE_CONSTRAINTS); - value = phone; + this.phone = phone; } @JsonValue public String get() { - return value; + return phone; } /** @@ -45,7 +45,7 @@ public static boolean isValidPhone(String test) { @Override public String toString() { - return value; + return phone; } @Override @@ -60,12 +60,12 @@ public boolean equals(Object other) { } Phone otherPhone = (Phone) other; - return value.equals(otherPhone.value); + return phone.equals(otherPhone.phone); } @Override public int hashCode() { - return value.hashCode(); + return phone.hashCode(); } } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 094c42cda82..9fccb85797f 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -48,10 +48,10 @@ public PersonCard(Person person, int displayedIndex) { super(FXML); this.person = person; id.setText(displayedIndex + ". "); - name.setText(person.getName().fullName); - phone.setText(person.getPhone().value); - address.setText(person.getAddress().value); - email.setText(person.getEmail().value); + name.setText(person.getName().name); + phone.setText(person.getPhone().phone); + address.setText(person.getAddress().address); + email.setText(person.getEmail().email); person.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 643a1d08069..b5dfdda69ee 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -119,7 +119,7 @@ public static void showPersonAtIndex(Model model, Index targetIndex) { assertTrue(targetIndex.getZeroBased() < model.getFilteredPersonList().size()); Person person = model.getFilteredPersonList().get(targetIndex.getZeroBased()); - final String[] splitName = person.getName().fullName.split("\\s+"); + final String[] splitName = person.getName().name.split("\\s+"); model.updateFilteredPersonList(new NameContainsKeywordsPredicate(Arrays.asList(splitName[0]))); assertEquals(1, model.getFilteredPersonList().size()); diff --git a/src/test/java/seedu/address/model/ModelManagerTest.java b/src/test/java/seedu/address/model/ModelManagerTest.java index 2cf1418d116..0ade27d9eb6 100644 --- a/src/test/java/seedu/address/model/ModelManagerTest.java +++ b/src/test/java/seedu/address/model/ModelManagerTest.java @@ -117,7 +117,7 @@ public void equals() { assertFalse(modelManager.equals(new ModelManager(differentAddressBook, userPrefs))); // different filteredList -> returns false - String[] keywords = ALICE.getName().fullName.split("\\s+"); + String[] keywords = ALICE.getName().name.split("\\s+"); modelManager.updateFilteredPersonList(new NameContainsKeywordsPredicate(Arrays.asList(keywords))); assertFalse(modelManager.equals(new ModelManager(addressBook, userPrefs))); diff --git a/src/test/java/seedu/address/testutil/PersonUtil.java b/src/test/java/seedu/address/testutil/PersonUtil.java index 90849945183..1e27ba9dbeb 100644 --- a/src/test/java/seedu/address/testutil/PersonUtil.java +++ b/src/test/java/seedu/address/testutil/PersonUtil.java @@ -30,10 +30,10 @@ public static String getAddCommand(Person person) { */ public static String getPersonDetails(Person person) { StringBuilder sb = new StringBuilder(); - sb.append(PREFIX_NAME + person.getName().fullName + " "); - sb.append(PREFIX_PHONE + person.getPhone().value + " "); - sb.append(PREFIX_EMAIL + person.getEmail().value + " "); - sb.append(PREFIX_ADDRESS + person.getAddress().value + " "); + sb.append(PREFIX_NAME + person.getName().name + " "); + sb.append(PREFIX_PHONE + person.getPhone().phone + " "); + sb.append(PREFIX_EMAIL + person.getEmail().email + " "); + sb.append(PREFIX_ADDRESS + person.getAddress().address + " "); person.getTags().stream().forEach( s -> sb.append(PREFIX_TAG + s.tagName + " ") ); @@ -45,10 +45,10 @@ public static String getPersonDetails(Person person) { */ public static String getEditPersonDescriptorDetails(EditPersonDescriptor descriptor) { StringBuilder sb = new StringBuilder(); - descriptor.getName().ifPresent(name -> sb.append(PREFIX_NAME).append(name.fullName).append(" ")); - descriptor.getPhone().ifPresent(phone -> sb.append(PREFIX_PHONE).append(phone.value).append(" ")); - descriptor.getEmail().ifPresent(email -> sb.append(PREFIX_EMAIL).append(email.value).append(" ")); - descriptor.getAddress().ifPresent(address -> sb.append(PREFIX_ADDRESS).append(address.value).append(" ")); + descriptor.getName().ifPresent(name -> sb.append(PREFIX_NAME).append(name.name).append(" ")); + descriptor.getPhone().ifPresent(phone -> sb.append(PREFIX_PHONE).append(phone.phone).append(" ")); + descriptor.getEmail().ifPresent(email -> sb.append(PREFIX_EMAIL).append(email.email).append(" ")); + descriptor.getAddress().ifPresent(address -> sb.append(PREFIX_ADDRESS).append(address.address).append(" ")); if (descriptor.getTags().isPresent()) { Set tags = descriptor.getTags().get(); if (tags.isEmpty()) { From 33f7ebb6299e173dadc059430fc68fd2ed24bcea Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Tue, 27 Feb 2024 02:05:15 +0800 Subject: [PATCH 12/16] Cleanup Phone.java --- src/main/java/seedu/address/model/person/Phone.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Phone.java b/src/main/java/seedu/address/model/person/Phone.java index 94e8abdb207..8241c050c19 100644 --- a/src/main/java/seedu/address/model/person/Phone.java +++ b/src/main/java/seedu/address/model/person/Phone.java @@ -3,8 +3,6 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; /** @@ -13,7 +11,6 @@ */ public class Phone { - public static final String MESSAGE_CONSTRAINTS = "Phone numbers should only contain numbers, and it should be at least 3 digits long"; public static final String VALIDATION_REGEX = "\\d{3,}"; @@ -24,8 +21,7 @@ public class Phone { * * @param phone A valid phone number. */ - @JsonCreator - public Phone(@JsonProperty String phone) { + public Phone(String phone) { requireNonNull(phone); checkArgument(isValidPhone(phone), MESSAGE_CONSTRAINTS); this.phone = phone; From 583b7311eb215fd73f9c91f63f692748c2ba59f0 Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Tue, 27 Feb 2024 02:20:08 +0800 Subject: [PATCH 13/16] Remove unnecessary getters --- src/main/java/seedu/address/model/person/Address.java | 6 +----- src/main/java/seedu/address/model/person/Email.java | 6 +----- src/main/java/seedu/address/model/person/Name.java | 7 +------ src/main/java/seedu/address/model/person/Phone.java | 6 +----- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Address.java b/src/main/java/seedu/address/model/person/Address.java index 18e902f5cdd..06894e14312 100644 --- a/src/main/java/seedu/address/model/person/Address.java +++ b/src/main/java/seedu/address/model/person/Address.java @@ -32,11 +32,6 @@ public Address(String address) { this.address = address; } - @JsonValue - private String get() { - return address; - } - /** * Returns true if a given string is a valid email. */ @@ -45,6 +40,7 @@ public static boolean isValidAddress(String test) { } @Override + @JsonValue public String toString() { return address; } diff --git a/src/main/java/seedu/address/model/person/Email.java b/src/main/java/seedu/address/model/person/Email.java index 53e5d3b6428..bdbd1902317 100644 --- a/src/main/java/seedu/address/model/person/Email.java +++ b/src/main/java/seedu/address/model/person/Email.java @@ -46,11 +46,6 @@ public Email(String email) { this.email = email; } - @JsonValue - private String get() { - return email; - } - /** * Returns if a given string is a valid email. */ @@ -59,6 +54,7 @@ public static boolean isValidEmail(String test) { } @Override + @JsonValue public String toString() { return email; } diff --git a/src/main/java/seedu/address/model/person/Name.java b/src/main/java/seedu/address/model/person/Name.java index 827856fccbb..fb559ab3c90 100644 --- a/src/main/java/seedu/address/model/person/Name.java +++ b/src/main/java/seedu/address/model/person/Name.java @@ -33,11 +33,6 @@ public Name(String name) { this.name = name; } - @JsonValue - private String get() { - return name; - } - /** * Returns true if a given string is a valid name. */ @@ -45,8 +40,8 @@ public static boolean isValidName(String test) { return test.matches(VALIDATION_REGEX); } - @Override + @JsonValue public String toString() { return name; } diff --git a/src/main/java/seedu/address/model/person/Phone.java b/src/main/java/seedu/address/model/person/Phone.java index 8241c050c19..b5aa0c4626c 100644 --- a/src/main/java/seedu/address/model/person/Phone.java +++ b/src/main/java/seedu/address/model/person/Phone.java @@ -27,11 +27,6 @@ public Phone(String phone) { this.phone = phone; } - @JsonValue - public String get() { - return phone; - } - /** * Returns true if a given string is a valid phone number. */ @@ -40,6 +35,7 @@ public static boolean isValidPhone(String test) { } @Override + @JsonValue public String toString() { return phone; } From 7ba691f1ef9f60ea3175a0f8ada5da2195b2351e Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Tue, 27 Feb 2024 02:29:01 +0800 Subject: [PATCH 14/16] Remove unnecessary annotation --- src/main/java/seedu/address/model/person/UniquePersonList.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/seedu/address/model/person/UniquePersonList.java b/src/main/java/seedu/address/model/person/UniquePersonList.java index 8f2b329872e..a6eac6f1174 100644 --- a/src/main/java/seedu/address/model/person/UniquePersonList.java +++ b/src/main/java/seedu/address/model/person/UniquePersonList.java @@ -6,7 +6,6 @@ import java.util.Iterator; import java.util.List; -import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @@ -92,7 +91,6 @@ public void setPersons(UniquePersonList replacement) { * Replaces the contents of this list with {@code persons}. * {@code persons} must not contain duplicate persons. */ - @JsonSetter public void setPersons(List persons) { requireAllNonNull(persons); if (!personsAreUnique(persons)) { From e2e21bf40d7cc7b11a40c54edccc0d9bc93b5243 Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Tue, 27 Feb 2024 18:38:13 +0800 Subject: [PATCH 15/16] Add null check for tagNames --- src/main/java/seedu/address/model/person/Person.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index fc20c5f0bfa..ceb804d169d 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -50,8 +50,10 @@ private Person(@JsonProperty("name") String name, @JsonProperty("phone") String this.phone = new Phone(phone); this.email = new Email(email); this.address = new Address(address); - for (String tagName : tagNames) { - this.tags.add(new Tag(tagName)); + if (tagNames != null) { + for (String tagName : tagNames) { + this.tags.add(new Tag(tagName)); + } } } From 10d3015ffc6c5c59058652b212327aa5bda33807 Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Tue, 27 Feb 2024 18:39:45 +0800 Subject: [PATCH 16/16] Remove non-null requirement for tagNames --- src/main/java/seedu/address/model/person/Person.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index ceb804d169d..3d496277935 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -45,7 +45,6 @@ public Person(Name name, Phone phone, Email email, Address address, Set tag private Person(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, @JsonProperty("tags") List tagNames) { - requireAllNonNull(name, phone, email, address, tagNames); this.name = new Name(name); this.phone = new Phone(phone); this.email = new Email(email);