Skip to content

Commit

Permalink
Merge pull request #127 from uberSaiyan/fix-json
Browse files Browse the repository at this point in the history
Fix JsonAdaptedCustomer
  • Loading branch information
yan-wl authored Oct 16, 2019
2 parents e4e802d + 2f34a3b commit e6454f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
2 changes: 0 additions & 2 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
//ReadOnlyDataBook<Customer> customerBook = SampleDataUtil.getSampleCustomerBook();
//ReadOnlyDataBook<Phone> phoneBook = SampleDataUtil.getSamplePhoneBook();
//ReadOnlyDataBook<Order> orderBook = SampleDataUtil.getSampleOrderBook();

return new ModelManager(initialCustomerData, initialPhoneData, initialOrderData, new ScheduleBook(), userPrefs);

}

private void initLogging(Config config) {
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/seedu/address/storage/JsonAdaptedCustomer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsonAdaptedTag> 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<JsonAdaptedTag> tagged) {
this.customerName = customerName;
this.contactNumber = contactNumber;
Expand All @@ -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()));
Expand All @@ -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<Tag> modelTags = new HashSet<>(customerTags);
return new Customer(modelCustomerName, modelContactNumber, modelEmail, modelTags);
Expand Down

0 comments on commit e6454f6

Please sign in to comment.