Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/main/java/com/force/api/ResourceRepresentation.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.force.api;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/com/force/api/ResourceRepresentationTest.java
Original file line number Diff line number Diff line change
@@ -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),'{');
}
}