diff --git a/src/main/java/com/force/api/ResourceRepresentation.java b/src/main/java/com/force/api/ResourceRepresentation.java index 2823dcb..c3f368b 100644 --- a/src/main/java/com/force/api/ResourceRepresentation.java +++ b/src/main/java/com/force/api/ResourceRepresentation.java @@ -1,6 +1,7 @@ package com.force.api; import java.io.IOException; +import java.io.InputStream; import java.util.List; import java.util.Map; @@ -69,6 +70,24 @@ public List asList() { } } + public String asJsonString() { + try { + Object o = jsonMapper.readValue(response.getStream(), Object.class); + return jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(o); + } catch (IOException e) { + e.printStackTrace(); + throw new ResourceException(e); + } + } + + public InputStream asStream() { + return response.getStream(); + } + + public byte[] asBytes() { + return response.getByte(); + } + /** * * @return the HTTP response code of the underlying request if it was between 200 and 299. Any code outside of that diff --git a/src/test/java/com/force/api/ResourceRepresentationTest.java b/src/test/java/com/force/api/ResourceRepresentationTest.java new file mode 100644 index 0000000..71c03dd --- /dev/null +++ b/src/test/java/com/force/api/ResourceRepresentationTest.java @@ -0,0 +1,29 @@ +package com.force.api; + +import org.junit.Before; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.*; + +public class ResourceRepresentationTest { + + ForceApi api; + String recordId; + + @Before + public void init() { + api = new ForceApi(new ApiConfig() + .setUsername(Fixture.get("username")) + .setPassword(Fixture.get("password"))); + recordId = api.query("SELECT id FROM Account",Account.class).getRecords().get(0).getId(); + } + + @Test + public void testRawJson() { + String jsonString = api.getSObject("account", recordId).asJsonString(); + // Pretty lame smoke test to see if we got some json back. + assertEquals(jsonString.charAt(0),'{'); + } +}