From 2f34a3b8833547cb186ae23bdc446d691974e983 Mon Sep 17 00:00:00 2001 From: uberSaiyan Date: Wed, 16 Oct 2019 20:11:08 +0800 Subject: [PATCH] Fix JsonAdaptedCustomer --- src/main/java/seedu/address/MainApp.java | 2 -- .../address/storage/JsonAdaptedCustomer.java | 30 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/main/java/seedu/address/MainApp.java b/src/main/java/seedu/address/MainApp.java index a31f65ec155..010874601d0 100644 --- a/src/main/java/seedu/address/MainApp.java +++ b/src/main/java/seedu/address/MainApp.java @@ -160,9 +160,7 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { //ReadOnlyDataBook customerBook = SampleDataUtil.getSampleCustomerBook(); //ReadOnlyDataBook phoneBook = SampleDataUtil.getSamplePhoneBook(); //ReadOnlyDataBook orderBook = SampleDataUtil.getSampleOrderBook(); - return new ModelManager(initialCustomerData, initialPhoneData, initialOrderData, new ScheduleBook(), userPrefs); - } private void initLogging(Config config) { diff --git a/src/main/java/seedu/address/storage/JsonAdaptedCustomer.java b/src/main/java/seedu/address/storage/JsonAdaptedCustomer.java index 8e7943ce3ea..65d69a6b004 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedCustomer.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedCustomer.java @@ -24,18 +24,18 @@ class JsonAdaptedCustomer { public static final String MISSING_FIELD_MESSAGE_FORMAT = "Customer's %s field is missing!"; - private final CustomerName customerName; - private final ContactNumber contactNumber; - private final Email email; + private final String customerName; + private final String contactNumber; + private final String email; private final List tagged = new ArrayList<>(); /** * Constructs a {@code JsonAdaptedCustomer} with the given customer details. */ @JsonCreator - public JsonAdaptedCustomer(@JsonProperty("customerName") CustomerName customerName, - @JsonProperty("contactNumber") ContactNumber contactNumber, - @JsonProperty("email") Email email, + public JsonAdaptedCustomer(@JsonProperty("customerName") String customerName, + @JsonProperty("contactNumber") String contactNumber, + @JsonProperty("email") String email, @JsonProperty("tagged") List tagged) { this.customerName = customerName; this.contactNumber = contactNumber; @@ -49,9 +49,9 @@ public JsonAdaptedCustomer(@JsonProperty("customerName") CustomerName customerNa * Converts a given {@code Customer} into this class for Jackson use. */ public JsonAdaptedCustomer(Customer source) { - customerName = source.getCustomerName(); - contactNumber = source.getContactNumber(); - email = source.getEmail(); + customerName = source.getCustomerName().fullName; + contactNumber = source.getContactNumber().value; + email = source.getEmail().value; tagged.addAll(source.getTags().stream() .map(JsonAdaptedTag::new) .collect(Collectors.toList())); @@ -72,27 +72,27 @@ public Customer toModelType() throws IllegalValueException { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, CustomerName.class.getSimpleName())); } - if (!CustomerName.isValidCustomerName(customerName.toString())) { + if (!CustomerName.isValidCustomerName(customerName)) { throw new IllegalValueException(CustomerName.MESSAGE_CONSTRAINTS); } - final CustomerName modelCustomerName = new CustomerName(customerName.toString()); + final CustomerName modelCustomerName = new CustomerName(customerName); if (contactNumber == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, ContactNumber.class.getSimpleName())); } - if (!ContactNumber.isValidContactNumber(contactNumber.toString())) { + if (!ContactNumber.isValidContactNumber(contactNumber)) { throw new IllegalValueException(ContactNumber.MESSAGE_CONSTRAINTS); } - final ContactNumber modelContactNumber = new ContactNumber(contactNumber.toString()); + final ContactNumber modelContactNumber = new ContactNumber(contactNumber); if (email == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName())); } - if (!Email.isValidEmail(email.toString())) { + if (!Email.isValidEmail(email)) { throw new IllegalValueException(Email.MESSAGE_CONSTRAINTS); } - final Email modelEmail = new Email(email.toString()); + final Email modelEmail = new Email(email); final Set modelTags = new HashSet<>(customerTags); return new Customer(modelCustomerName, modelContactNumber, modelEmail, modelTags);