XeroAPI / Xero-Java

Official Java client for use with Xero API
MIT License
75 stars 87 forks source link

Getting Wrong date format Exception when creating an invoice #333

Closed arifainchtein closed 1 year ago

arifainchtein commented 1 year ago

SDK you're using (please complete the following information):

com.fasterxml.jackson.databind.JsonMappingException: Wrong date format (through reference chain: com.xero.models.accounting.Invoices["Invoices"]->java.util.ArrayList[0]-> Caused by: java.lang.IllegalArgumentException: Wrong date format

To Reproduce Steps to reproduce the behavior:

Run this code:

   ` Invoice invoice = new Invoice();
    invoice.setType(com.xero.models.accounting.Invoice.TypeEnum.ACCREC);
    invoice.setContact(contact);
    SimpleDateFormat invoiceDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String dateValue = invoiceDateFormat.format(new Date());
    System.out.println("line 400, dateValue=" + dateValue);
    invoice.setDate(dateValue);
    YearMonth ym = YearMonth.now( ZoneId.of( "Australia/Melbourne" ) ) ;
    YearMonth ymNext = ym.plusMonths( 1 ) ;
    java.time.LocalDate ld = ymNext.atEndOfMonth() ;
    String dueDateValue = ld.toString() ;
    invoice.setDueDate(dueDateValue);
    System.out.println("line 407, dueDateValue=" + dueDateValue);
    invoice.setLineItems(lineItems);
    invoice.setReference("Website Design");
    invoice.setStatus(com.xero.models.accounting.Invoice.StatusEnum.DRAFT);

    Invoices invoices = new Invoices();
    invoices.addInvoicesItem(invoice);
    boolean summarizeErrors=false;
    int unitdp=2;
    try {
        Invoices result = accountingApi.createInvoices(access_token, xero_tenant_id, invoices, summarizeErrors, unitdp);
        System.out.println(result);
    } catch (Exception e) {
        System.err.println("Exception when calling AccountingApi#createInvoices");

        e.printStackTrace();
    }`

in the code above, the outout of the System.out.println is: line 400, dateValue=2023-03-16 line 407, dueDateValue=2023-04-30

Expected behavior A clear and concise description of what you expected to happen. The invoice should be created

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

github-actions[bot] commented 1 year ago

PETOSS-282

github-actions[bot] commented 1 year ago

Thanks for raising an issue, a ticket has been created to track your request

rdemarco-xero commented 1 year ago

Hi @arifainchtein - in your code you are providing the date as a String. You need to provide a LocalDate type instead.