Author: hsaputra
Date: Tue Jun 19 17:55:51 2012
New Revision: 1351787
URL: http://svn.apache.org/viewvc?rev=1351787&view=rev
Log:
SHINDIG-1807 Fix the JsonUtil to also consider methods prefixed with is as
accessor to properties.
Modified:
shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonUtil.java
shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonDelete.json
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonGroup.json
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonIds.json
Modified:
shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonUtil.java
URL:
http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonUtil.java?rev=1351787&r1=1351786&r2=1351787&view=diff
==============================================================================
---
shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonUtil.java
(original)
+++
shindig/trunk/java/common/src/main/java/org/apache/shindig/common/JsonUtil.java
Tue Jun 19 17:55:51 2012
@@ -21,6 +21,7 @@ import com.google.common.cache.CacheBuil
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang3.text.WordUtils;
import org.json.JSONObject;
import java.lang.reflect.InvocationTargetException;
@@ -102,7 +103,10 @@ public final class JsonUtil {
if (property == null) {
String name = method.getName();
if (name.startsWith("get") && (!EXCLUDE_METHODS.contains(name))) {
- return name.substring(3, 4).toLowerCase() + name.substring(4);
+ return WordUtils.uncapitalize(name.substring(3));
+ } else if (name.startsWith("is") && name.length() > 2 &&
+ Character.isUpperCase(name.charAt(2))) {
+ return WordUtils.uncapitalize(name.substring(2));
}
return null;
} else {
Modified:
shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java
URL:
http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java?rev=1351787&r1=1351786&r2=1351787&view=diff
==============================================================================
---
shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java
(original)
+++
shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java
Tue Jun 19 17:55:51 2012
@@ -259,7 +259,7 @@ public class JsonRpcServlet extends ApiS
return dispatcher.getRpcHandler(rpc);
}
- Object getJSONResponse(String key, ResponseItem responseItem) {
+ protected Object getJSONResponse(String key, ResponseItem responseItem) {
Map<String, Object> result = Maps.newHashMap();
if (key != null) {
result.put("id", key);
@@ -303,7 +303,7 @@ public class JsonRpcServlet extends ApiS
}
/** Map of old-style error titles */
- private static final Map<Integer, String> errorTitles =
ImmutableMap.<Integer, String> builder()
+ protected static final Map<Integer, String> errorTitles =
ImmutableMap.<Integer, String> builder()
.put(HttpServletResponse.SC_NOT_IMPLEMENTED, "notImplemented")
.put(HttpServletResponse.SC_UNAUTHORIZED, "unauthorized")
.put(HttpServletResponse.SC_FORBIDDEN, "forbidden")
@@ -315,7 +315,7 @@ public class JsonRpcServlet extends ApiS
// TODO(doll): Refactor the responseItem so that the fields on it line up
with this format.
// Then we can use the general converter to output the response to the
client and we won't
// be harcoded to json.
- private Object getErrorJson(ResponseItem responseItem) {
+ protected Object getErrorJson(ResponseItem responseItem) {
Map<String, Object> error = new HashMap<String, Object>(2, 1);
error.put("code", responseItem.getErrorCode());
@@ -347,12 +347,12 @@ public class JsonRpcServlet extends ApiS
servletResponse.setStatus(responseItem.getErrorCode());
}
- private void sendBadRequest(Throwable t, HttpServletResponse response)
throws IOException {
+ protected void sendBadRequest(Throwable t, HttpServletResponse response)
throws IOException {
sendError(response, new ResponseItem(HttpServletResponse.SC_BAD_REQUEST,
"Invalid input - " + t.getMessage()));
}
- private void sendJsonParseError(JSONException e, HttpServletResponse
response) throws IOException {
+ protected void sendJsonParseError(JSONException e, HttpServletResponse
response) throws IOException {
sendError(response, new ResponseItem(HttpServletResponse.SC_BAD_REQUEST,
"Invalid JSON - " + e.getMessage()));
}
Modified:
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonDelete.json
URL:
http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonDelete.json?rev=1351787&r1=1351786&r2=1351787&view=diff
==============================================================================
---
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonDelete.json
(original)
+++
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonDelete.json
Tue Jun 19 17:55:51 2012
@@ -1,6 +1,10 @@
{
- "totalResults": 2,
+ "itemsPerPage": 2,
+ "sorted": true,
"startIndex": 0,
+ "totalResults": 2,
+ "filtered": true,
+ "updatedSince": true,
"list": [{
"id": "activity2",
"title": "John posted a new photo album.",
@@ -125,6 +129,5 @@
"gadget":
"http://localhost:8080/samplecontainer/examples/embeddedexperiences/BlogViewer.xml"
}
}
- }],
- "itemsPerPage": 2
+ }]
}
\ No newline at end of file
Modified:
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonGroup.json
URL:
http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonGroup.json?rev=1351787&r1=1351786&r2=1351787&view=diff
==============================================================================
---
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonGroup.json
(original)
+++
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonGroup.json
Tue Jun 19 17:55:51 2012
@@ -1,6 +1,10 @@
{
- "totalResults": 3,
+ "itemsPerPage": 3,
+ "sorted": true,
"startIndex": 0,
+ "totalResults": 3,
+ "filtered": true,
+ "updatedSince": true,
"list": [{
"id": "activity1",
"title": "John shared new photos with you",
@@ -161,6 +165,5 @@
"gadget":
"http://localhost:8080/samplecontainer/examples/embeddedexperiences/BlogViewer.xml"
}
}
- }],
- "itemsPerPage": 3
+ }]
}
\ No newline at end of file
Modified:
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonIds.json
URL:
http://svn.apache.org/viewvc/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonIds.json?rev=1351787&r1=1351786&r2=1351787&view=diff
==============================================================================
---
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonIds.json
(original)
+++
shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/fixtures/ActivityEntryJsonIds.json
Tue Jun 19 17:55:51 2012
@@ -1,6 +1,10 @@
{
- "startIndex":0,
- "totalResults":2,
+ "itemsPerPage": 2,
+ "sorted": true,
+ "startIndex": 0,
+ "totalResults": 2,
+ "filtered": true,
+ "updatedSince": true,
"list":[
{
"id": "activity1",
@@ -114,6 +118,5 @@
}
}
}
- ],
- "itemsPerPage":2
+ ]
}
\ No newline at end of file