i have succesfully parse my JSON data. but now i want data back from following APEX method "getCustomerData()" like below:
DxModel[id=2, [email protected], first_name=clerk, last_name=dx, BillingAddress[city=Chicago, region=IL, postcode=60622, phone=0000000000]]
here is my model class:
global with sharing class DxModel {
/* inner Classes' Instances */
public BillingAddress billing_address {get;set;}
public List<Addresses> addresses {get;set;}
public String id {get;set;}
public String email {get;set;}
public String first_name {get;set;}
public String last_name {get;set;}
/* inner class */
global with sharing class BillingAddress{
public String city {get;set;}
public String state {get;set;}
public String postcode {get;set;}
public String phone {get;set;}
}
global with sharing class Addresses{
public String city {get;set;}
public Region region {get;set;}
public String postcode {get;set;}
public String telephone {get;set;}
}
global with sharing class Region{
public String region_code {get;set;}
}
}
is there any way to assign value from "Region" class and from "Addresses" class to "BillingAddress" class so i can get above output
here is my JSON data:
{"id":2,"created_at":"2016-06-30 09:59:12","updated_at":"2016-06-30 11:11:56","created_in":"Default Store View","email":"[email protected]","firstname":"clerk","lastname":"dx","gender":1,"store_id":1,"website_id":1,"addresses":[{"region":{"region_code":"IL"},"street":["123 main street","1050 Marshfield Ave #3"],"company":"Jhon DX","telephone":"0000000000","postcode":"60622","city":"Chicago","firstname":"clerk","lastname":"dx","default_billing":true}
This is my APEX method:
public List<DxModel> getCustomerData(){
parser = JSON.createParser("My JSON DATA");
List<DxModel> customerList = new List<DxModel>();
while (parser.nextToken() != null) {
if (parser.getCurrentToken() == JSONToken.START_ARRAY) {
while(parser.nextToken() != null) {
if(parser.getCurrentToken() == JSONToken.START_OBJECT) {
DxModel customer = (DxModel)parser.readValueAs(DxModel.class);
customerList.add(customer);
}
}
}
}
return customerList;
}
Address
how would you determine whichAddress
has theRegion
you want for theBillingAddress
?