Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apex class to XML Format is not as expected #5

Open
sarava77 opened this issue Aug 23, 2017 · 2 comments
Open

Apex class to XML Format is not as expected #5

sarava77 opened this issue Aug 23, 2017 · 2 comments

Comments

@sarava77
Copy link

No description provided.

@sarava77 sarava77 changed the title Apex class to XL Apex class to XML Format is not as expected Aug 23, 2017
@sarava77
Copy link
Author

sarava77 commented Aug 23, 2017

I want allocate the created Credit Notes to invoice

<Allocations>
 <Allocation>
   <AppliedAmount>60.50</AppliedAmount>
   <Invoice>
     <InvoiceID>f5832195-5cd3-4660-ad3f-b73d9c64f263</InvoiceID>
   </Invoice>
 </Allocation>
</Allocations>

So I have created the class below structure

public class JSON2Apex {

public Allocation Allocation=new Allocation();

public class Allocation {
public String AppliedAmount;
public Invoice Invoice=new Invoice();
}

public class Invoice {
public String InvoiceID;
}

}

This is the code I am executing in Salesforce developer console

String consumerKey;
HttpResponse response;
Xero_Settings__c xeroSettings=Xero_Settings__c.getInstance('UKINC');
consumerKey = xeroSettings.Consumer_Key__c;
JSON2Apex js=new JSON2Apex ();
JSON2Apex.Allocation alt=new JSON2Apex.Allocation();
alt.AppliedAmount='1.0';
alt.Invoice.InvoiceID='test';
js.Allocation=alt;String xmlInvoiceString = XeroXmlUtility.serialize(js, 'Allocations');
System.debug('*****************'+xmlInvoiceString);

And the Output structure is coming like below


<?xml version="1.0" encoding="UTF-8"?>
<Allocations>
  <Allocation>
     <AppliedAmount>1.0</AppliedAmount>
  </Allocation>
  <Invoice>
     <InvoiceID>test</InvoiceID>
  </Invoice>
</Allocations>

This Structure is not as expected there is some issue , Can any one know how to fix this.

@danielbprobert
Copy link

i'm doing something similar but using

have you public class for allocation like this:

public class Allocation {
public String AppliedAmount;
public XeroInvoice Invoice;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants