Author: ssievers
Date: Tue Nov 19 12:51:54 2013
New Revision: 1543409
URL: http://svn.apache.org/r1543409
Log:
SHINDIG-1947 | Bridge methods should be ignored when finding property setter
methods for JSON serialization | Patch from Andreas Kohn. Thanks!
Modified:
shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanJsonConverter.java
shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterTest.java
Modified:
shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanJsonConverter.java
URL:
http://svn.apache.org/viewvc/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanJsonConverter.java?rev=1543409&r1=1543408&r2=1543409&view=diff
==============================================================================
---
shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanJsonConverter.java
(original)
+++
shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanJsonConverter.java
Tue Nov 19 12:51:54 2013
@@ -48,6 +48,7 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
@@ -104,11 +105,12 @@ public class BeanJsonConverter implement
JsonSerializer.append(buf, pojo);
}
- private static String getPropertyName(Method setter) {
+ @VisibleForTesting
+ protected static String getPropertyName(Method setter) {
JsonProperty property = setter.getAnnotation(JsonProperty.class);
if (property == null) {
String name = setter.getName();
- if (name.startsWith("set") && !Modifier.isStatic(setter.getModifiers()))
{
+ if (name.startsWith("set") && !Modifier.isStatic(setter.getModifiers())
&& !setter.isBridge()) {
return name.substring(3, 4).toLowerCase() + name.substring(4);
}
return null;
Modified:
shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterTest.java
URL:
http://svn.apache.org/viewvc/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterTest.java?rev=1543409&r1=1543408&r2=1543409&view=diff
==============================================================================
---
shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterTest.java
(original)
+++
shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterTest.java
Tue Nov 19 12:51:54 2013
@@ -31,6 +31,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -46,6 +47,18 @@ public class BeanJsonConverterTest exten
beanJsonConverter = new BeanJsonConverter(Guice.createInjector());
}
+ public interface GenericInterface<T> {
+ void setT(T value);
+ }
+
+ public static class GenericObject implements GenericInterface<String> {
+ String value;
+
+ public void setT(String value) {
+ this.value = value;
+ }
+ }
+
public static class TestObject {
static String staticValue;
String hello;
@@ -202,4 +215,12 @@ public class BeanJsonConverterTest exten
ExtendableTestObject.class);
assertTrue(data.isEmpty());
}
+
+ @Test
+ public void testGetPropertyNameOfBridgeMethod() throws
NoSuchMethodException, SecurityException {
+ Method bridgeSetter = GenericObject.class.getMethod("setT", Object.class);
+ assertNull(BeanJsonConverter.getPropertyName(bridgeSetter));
+ Method realSetter = GenericObject.class.getMethod("setT", String.class);;
+ assertEquals("t", BeanJsonConverter.getPropertyName(realSetter));
+ }
}