Author: chico
Date: Thu Mar 19 17:44:30 2009
New Revision: 756108
URL: http://svn.apache.org/viewvc?rev=756108&view=rev
Log:
SHINDIG-985 by me: Fixed BeanJsonConverter to use underlying injected class
instead of type interface. Also includes unit test to ensure this issue doesn't
re-occur.
Added:
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterInjectedClassTest.java
(with props)
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanJsonConverter.java
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanJsonConverter.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanJsonConverter.java?rev=756108&r1=756107&r2=756108&view=diff
==============================================================================
---
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanJsonConverter.java
(original)
+++
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/BeanJsonConverter.java
Thu Mar 19 17:44:30 2009
@@ -238,7 +238,7 @@
private Object convertToClass(JSONObject in, Class<?> type) {
Object out = injector.getInstance(type);
- for (Map.Entry<String, Method> entry : getSetters(type).entrySet()) {
+ for (Map.Entry<String, Method> entry :
getSetters(out.getClass()).entrySet()) {
Object value = in.opt(entry.getKey());
if (value != null) {
Method method = entry.getValue();
Added:
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterInjectedClassTest.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterInjectedClassTest.java?rev=756108&view=auto
==============================================================================
---
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterInjectedClassTest.java
(added)
+++
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterInjectedClassTest.java
Thu Mar 19 17:44:30 2009
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.shindig.protocol.conversion;
+
+import junit.framework.TestCase;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+
+/**
+ * The Class BeanJsonConverterInjectedClassTest.
+ */
+public class BeanJsonConverterInjectedClassTest extends TestCase {
+
+ /** The bean json converter. */
+ private BeanJsonConverter beanJsonConverter;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ this.beanJsonConverter = new BeanJsonConverter(Guice.createInjector(new
TestModule()));
+ }
+
+ /**
+ * Test json conversion of a TestInterface into a TestObject
+ *
+ * @throws Exception the exception
+ */
+ public void testJsonToObject() throws Exception {
+ String json = "{x:'xValue',y:'yValue'}";
+ TestObject object = (TestObject) beanJsonConverter.convertToObject(json,
TestInterface.class);
+ assertNotNull("expected 'x' field not set after json conversion",
object.getX());
+ assertNotNull("expected 'y' field not set after json conversion",
object.getY());
+ }
+
+ /**
+ * TestModule that binds TestObject to TestInterface
+ */
+ private static class TestModule extends AbstractModule {
+ /* (non-Javadoc)
+ * @see com.google.inject.AbstractModule#configure()
+ */
+ @Override
+ protected void configure() {
+ bind(TestInterface.class).to(TestObject.class);
+ }
+ }
+
+ /**
+ * TestInterface.
+ */
+ public interface TestInterface {
+ public String getX();
+ public void setX(String x);
+ }
+
+ /**
+ * TestObject.
+ */
+ public static class TestObject implements TestInterface {
+
+ private String x;
+ private String y;
+
+ public String getX() {
+ return x;
+ }
+ public void setX(String x) {
+ this.x = x;
+ }
+
+ public String getY() {
+ return y;
+ }
+ public void setY(String y) {
+ this.y = y;
+ }
+ }
+
+}
Propchange:
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterInjectedClassTest.java
------------------------------------------------------------------------------
svn:eol-style = native