Source:
<code>public void shouldSerializeToJson() throws JsonProcessingException { final ObjectMapper mapper = JsonUtils.createObjectMapper(); mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); final ObjectWriter writer = mapper.writerFor(SObjectTree.class); final SObjectTree tree = new SObjectTree(); final SObjectNode account1 = new SObjectNode(tree, simpleAccount); account1.addChild("Contacts", smith); account1.addChild("Contacts", evans); tree.addNode(account1); final SObjectNode account2 = new SObjectNode(tree, simpleAccount2); tree.addNode(account2); final String json = writer.writeValueAsString(tree); assertEquals("Should serialize to JSON as in Salesforce example", <START> "{\"records\":[{\"Industry\":\"Banking\",\"Name\":\"SampleAccount\",\"NumberOfEmployees\":100,\"Phone\":\"1234567890\",\"Website\":\"www.salesforce.com\",\"attributes\":{\"referenceId\":\"ref1\",\"type\":\"Account\"},\"Contacts\":{\"records\":[{\"Email\":\"sample@salesforce.com\",\"LastName\":\"Smith\",\"Title\":\"President\",\"attributes\":{\"referenceId\":\"ref2\",\"type\":\"Contact\"}},{\"Email\":\"sample@salesforce.com\",\"LastName\":\"Evans\",\"Title\":\"Vice President\",\"attributes\":{\"referenceId\":\"ref3\",\"type\":\"Contact\"}}]}},{\"Industry\":\"Banking\",\"Name\":\"SampleAccount2\",\"NumberOfEmployees\":100,\"Phone\":\"1234567890\",\"Website\":\"www.salesforce2.com\",\"attributes\":{\"referenceId\":\"ref4\",\"type\":\"Account\"}}]}", <END> json); }</code><technical_language>a bit easier read before, format this a bit nicer</technical_language>

Target:
public void shouldSerializeToJson() throws JsonProcessingException { final ObjectMapper mapper = JsonUtils.createObjectMapper(); mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); final ObjectWriter writer = mapper.writerFor(SObjectTree.class); final SObjectTree tree = new SObjectTree(); final SObjectNode account1 = new SObjectNode(tree, simpleAccount); account1.addChild("Contacts", smith); account1.addChild("Contacts", evans); tree.addNode(account1); final SObjectNode account2 = new SObjectNode(tree, simpleAccount2); tree.addNode(account2); final String json = writer.writeValueAsString(tree); assertEquals("Should serialize to JSON as in Salesforce example", "{" + "\"records\":[" + "{" + "\"Industry\":\"Banking\"," + "\"Name\":\"SampleAccount\"," + "\"NumberOfEmployees\":100," + "\"Phone\":\"1234567890\"," + "\"Website\":\"www.salesforce.com\"," + "\"attributes\":{" + "\"referenceId\":\"ref1\"," + "\"type\":\"Account\"" + "}," + "\"Contacts\":{" + "\"records\":[" + "{" + "\"Email\":\"sample@salesforce.com\"," + "\"LastName\":\"Smith\"," + "\"Title\":\"President\"," + "\"attributes\":{" + "\"referenceId\":\"ref2\"," + "\"type\":\"Contact\"" + "}" + "}," + "{" + "\"Email\":\"sample@salesforce.com\"," + "\"LastName\":\"Evans\"," + "\"Title\":\"Vice President\"," + "\"attributes\":{" + "\"referenceId\":\"ref3\"," + "\"type\":\"Contact\"" + "}" + "}" + "]" + "}" + "}," + "{" + "\"Industry\":\"Banking\"," + "\"Name\":\"SampleAccount2\"," + "\"NumberOfEmployees\":100," + "\"Phone\":\"1234567890\"," + "\"Website\":\"www.salesforce2.com\"," + "\"attributes\":{" + "\"referenceId\":\"ref4\"," + "\"type\":\"Account\"" + "}" + "}" + "]" + "}", json); }