Skip to content

Commit

Permalink
Reusing existing ObjectMapper in RestJsonClient.
Browse files Browse the repository at this point in the history
Don't create new ObjectMapper's - one is sufficient.
ObjectMapper.readValue can use an InputStream directly, no need to convert to String first.
  • Loading branch information
candrews committed Aug 24, 2011
1 parent 34d5930 commit 5052e7c
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/com/andrewshu/android/reddit/common/RestJsonClient.java
Expand Up @@ -26,7 +26,7 @@ public static JsonNode connect(String url)
// Execute the request
HttpResponse response;

ObjectMapper json = new ObjectMapper();
ObjectMapper json = Common.getObjectMapper();
JsonNode data = null;
try {
response = httpclient.execute(httpget);
Expand All @@ -37,10 +37,8 @@ public static JsonNode connect(String url)

// A Simple JSON Response Read
InputStream instream = entity.getContent();
String result= convertStreamToString(instream);

json = new ObjectMapper();
data = json.readValue(result, JsonNode.class);
data = json.readValue(instream, JsonNode.class);

instream.close();
}
Expand Down

1 comment on commit 5052e7c

@talklittle
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good change. I would also remove the now-unused convertStreamToString method.

Please sign in to comment.