jesperfj/force-rest-api — pull request #3 by anandbn (2012-04-13 00:00:54+00:00)
Title: Relationship query handling

Added code to normalize the JsonResponse in order to handle relationship queries. Allows for developers to do this:

ForceRestApi api = new ForceRestApi(apiConfig,apiSession);
QueryResult result = api.query( "select Id,Name,Comments__c,(select Id,Line_Number__c,"+
"Item_Id__c,Quantity__c from Order_Line_Items__r) "
"from Order__c",
Order.class
);
for(Order order:result.getRecords()){
for(OrderLineItem item: order;getOrderLineItems()){

//process line items
}
}

JSON Response returned by REST API:

{
"totalSize" : 1,
"done" : true,
"records" : [ {
"attributes" : {
"type" : "Account",
"url" : "/services/data/v24.0/sobjects/Account/0017000000TcinJAAR"
},
"Id" : "0017000000TcinJAAR",
"Name" : "test_acc_04_01",
"Contacts" : {
"totalSize" : 1,
"done" : true,
"records" : [ {
"attributes" : {
"type" : "Contact",
"url" : "/services/data/v24.0/sobjects/Contact/0037000000zcgHwAAI"
},
"Id" : "0037000000zcgHwAAI",
"Email" : "anand.bn@gmail.com",
"FirstName" : "Anand"
} ]
}
} ]
}

JSON Response after normalization:

{
"totalSize" : 1,
"done" : true,
"records" : [ {
"attributes" : {
"type" : "Account",
"url" : "/services/data/v24.0/sobjects/Account/0017000000TcinJAAR"
},
"Id" : "0017000000TcinJAAR",
"Name" : "test_acc_04_01",
"Contacts" : [ {
"attributes" : {
"type" : "Contact",
"url" : "/services/data/v24.0/sobjects/Contact/0037000000zcgHwAAI"
},
"Id" : "0037000000zcgHwAAI",
"Email" : "anand.bn@gmail.com",
"FirstName" : "Anand"
} ]
} ]
}