wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jra...@apache.org
Subject svn commit: r1001822 - in /incubator/wink/trunk/wink-providers/wink-jackson-provider: ./ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/wink/ src/main/java/org/apache/wink/providers/ src/main/java/org/apa...
Date Mon, 27 Sep 2010 17:21:17 GMT
Author: jramos
Date: Mon Sep 27 17:21:16 2010
New Revision: 1001822

URL: http://svn.apache.org/viewvc?rev=1001822&view=rev
Log:
[WINK-299] Add WinkJacksonJaxbJsonProvider provider and corresponding wink-aplication file

Added:
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/java/
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/java/org/
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/java/org/apache/
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/java/org/apache/wink/
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/java/org/apache/wink/providers/
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/java/org/apache/wink/providers/jackson/
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/java/org/apache/wink/providers/jackson/WinkJacksonJaxbJsonProvider.java
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/resources/
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/resources/META-INF/
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/resources/META-INF/wink-application
Modified:
    incubator/wink/trunk/wink-providers/wink-jackson-provider/pom.xml
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JAXBCollectionJSONTest.java
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonJAXBTest.java
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonJSON4JBattleTest.java
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonPOJOTest.java
    incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/PolymorphicTest.java

Modified: incubator/wink/trunk/wink-providers/wink-jackson-provider/pom.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-jackson-provider/pom.xml?rev=1001822&r1=1001821&r2=1001822&view=diff
==============================================================================
--- incubator/wink/trunk/wink-providers/wink-jackson-provider/pom.xml (original)
+++ incubator/wink/trunk/wink-providers/wink-jackson-provider/pom.xml Mon Sep 27 17:21:16
2010
@@ -60,6 +60,7 @@
         <dependency>
             <groupId>org.apache.wink</groupId>
             <artifactId>wink-component-test-support</artifactId>
+            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
@@ -69,6 +70,7 @@
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-test</artifactId>
+            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>

Added: incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/java/org/apache/wink/providers/jackson/WinkJacksonJaxbJsonProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/java/org/apache/wink/providers/jackson/WinkJacksonJaxbJsonProvider.java?rev=1001822&view=auto
==============================================================================
--- incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/java/org/apache/wink/providers/jackson/WinkJacksonJaxbJsonProvider.java
(added)
+++ incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/java/org/apache/wink/providers/jackson/WinkJacksonJaxbJsonProvider.java
Mon Sep 27 17:21:16 2010
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * 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.wink.providers.jackson;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
+import org.codehaus.jackson.map.AnnotationIntrospector;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector;
+import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
+
+@Provider
+@Consumes( {MediaType.APPLICATION_JSON, "text/json"})
+@Produces( {MediaType.APPLICATION_JSON, "text/json"})
+public class WinkJacksonJaxbJsonProvider implements MessageBodyReader<Object>, MessageBodyWriter<Object>
{
+
+    JacksonJaxbJsonProvider jacksonProvider;
+
+    public WinkJacksonJaxbJsonProvider() {
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.getSerializationConfig().setSerializationInclusion(Inclusion.NON_NULL);
+        AnnotationIntrospector pair =
+            new AnnotationIntrospector.Pair(new JaxbAnnotationIntrospector(),
+                                            new JacksonAnnotationIntrospector());
+        mapper.getDeserializationConfig().setAnnotationIntrospector(pair);
+        mapper.getSerializationConfig().setAnnotationIntrospector(pair);
+        this.jacksonProvider = new JacksonJaxbJsonProvider();
+        jacksonProvider.setMapper(mapper);
+    }
+
+    public long getSize(Object t,
+                        Class<?> type,
+                        Type genericType,
+                        Annotation[] annotations,
+                        MediaType mediaType) {
+        return jacksonProvider.getSize(t, type, genericType, annotations, mediaType);
+    }
+
+    public boolean isWriteable(Class<?> type,
+                               Type genericType,
+                               Annotation[] annotations,
+                               MediaType mediaType) {
+        return jacksonProvider.isWriteable(type, genericType, annotations, mediaType);
+    }
+
+    public void writeTo(Object t,
+                        Class<?> type,
+                        Type genericType,
+                        Annotation[] annotations,
+                        MediaType mediaType,
+                        MultivaluedMap<String, Object> httpHeaders,
+                        OutputStream entityStream) throws IOException {
+        jacksonProvider.writeTo(t,
+                                type,
+                                genericType,
+                                annotations,
+                                mediaType,
+                                httpHeaders,
+                                entityStream);
+    }
+
+    public boolean isReadable(Class<?> type,
+                              Type genericType,
+                              Annotation[] annotations,
+                              MediaType mediaType) {
+        return jacksonProvider.isReadable(type, genericType, annotations, mediaType);
+    }
+
+    public Object readFrom(Class<Object> type,
+                           Type genericType,
+                           Annotation[] annotations,
+                           MediaType mediaType,
+                           MultivaluedMap<String, String> httpHeaders,
+                           InputStream entityStream) throws IOException {
+        return jacksonProvider.readFrom(type,
+                                        genericType,
+                                        annotations,
+                                        mediaType,
+                                        httpHeaders,
+                                        entityStream);
+    }
+
+}

Added: incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/resources/META-INF/wink-application
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/resources/META-INF/wink-application?rev=1001822&view=auto
==============================================================================
--- incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/resources/META-INF/wink-application
(added)
+++ incubator/wink/trunk/wink-providers/wink-jackson-provider/src/main/resources/META-INF/wink-application
Mon Sep 27 17:21:16 2010
@@ -0,0 +1,20 @@
+##
+## 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.
+##
+
+org.apache.wink.providers.jackson.WinkJacksonJaxbJsonProvider

Modified: incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JAXBCollectionJSONTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JAXBCollectionJSONTest.java?rev=1001822&r1=1001821&r2=1001822&view=diff
==============================================================================
--- incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JAXBCollectionJSONTest.java
(original)
+++ incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JAXBCollectionJSONTest.java
Mon Sep 27 17:21:16 2010
@@ -37,12 +37,11 @@ import javax.xml.datatype.XMLGregorianCa
 import javax.xml.namespace.QName;
 
 import org.apache.wink.common.model.atom.AtomEntry;
+import org.apache.wink.providers.jackson.WinkJacksonJaxbJsonProvider;
 import org.apache.wink.providers.jackson.internal.jaxb.Person;
 import org.apache.wink.providers.json.JSONUtils;
 import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
 import org.apache.wink.test.mock.MockRequestConstructor;
-import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
-import org.codehaus.jackson.map.SerializationConfig.Feature;
 import org.json.JSONArray;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.mock.web.MockHttpServletResponse;
@@ -154,11 +153,7 @@ public class JAXBCollectionJSONTest exte
 
     @Override
     protected Object[] getSingletons() {
-    	JacksonJaxbJsonProvider jacksonProvider = new JacksonJaxbJsonProvider();
-    	jacksonProvider.configure(Feature.WRITE_NULL_MAP_VALUES, Boolean.FALSE);
-    	jacksonProvider.configure(Feature.WRITE_NULL_PROPERTIES, Boolean.FALSE);
-    	jacksonProvider.configure(Feature.WRITE_DATES_AS_TIMESTAMPS, Boolean.TRUE);
-        return new Object[] {jacksonProvider};
+        return new Object[] {new WinkJacksonJaxbJsonProvider()};
     }
 
     @Path("/test/person")

Modified: incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonJAXBTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonJAXBTest.java?rev=1001822&r1=1001821&r2=1001822&view=diff
==============================================================================
--- incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonJAXBTest.java
(original)
+++ incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonJAXBTest.java
Mon Sep 27 17:21:16 2010
@@ -32,12 +32,11 @@ import javax.xml.bind.JAXBElement;
 
 import org.apache.wink.common.model.atom.AtomEntry;
 import org.apache.wink.common.model.synd.SyndEntry;
+import org.apache.wink.providers.jackson.WinkJacksonJaxbJsonProvider;
 import org.apache.wink.providers.jackson.internal.jaxb.Person;
 import org.apache.wink.providers.json.JSONUtils;
 import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
 import org.apache.wink.test.mock.MockRequestConstructor;
-import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
-import org.codehaus.jackson.map.SerializationConfig.Feature;
 import org.json.JSONObject;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.mock.web.MockHttpServletResponse;
@@ -54,9 +53,7 @@ public class JacksonJAXBTest extends Moc
 
     @Override
     protected Object[] getSingletons() {
-        JacksonJaxbJsonProvider jacksonProvider = new JacksonJaxbJsonProvider();
-        jacksonProvider.configure(Feature.WRITE_NULL_PROPERTIES, Boolean.FALSE);
-        return new Object[] {jacksonProvider};
+        return new Object[] {new WinkJacksonJaxbJsonProvider()};
     }
 
     @Path("/test/person")
@@ -168,8 +165,6 @@ public class JacksonJAXBTest extends Moc
                                                         "application/json");
         MockHttpServletResponse response = invoke(request);
         assertEquals(200, response.getStatus());
-        System.out.println(new JSONObject(ENTRY_JSON).toString(4));
-        System.out.println(new JSONObject(response.getContentAsString()).toString(4));
         assertTrue(JSONUtils.equals(JSONUtils.objectForString(ENTRY_JSON), JSONUtils
             .objectForString(response.getContentAsString())));
     }

Modified: incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonJSON4JBattleTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonJSON4JBattleTest.java?rev=1001822&r1=1001821&r2=1001822&view=diff
==============================================================================
--- incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonJSON4JBattleTest.java
(original)
+++ incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonJSON4JBattleTest.java
Mon Sep 27 17:21:16 2010
@@ -26,11 +26,11 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 
+import org.apache.wink.providers.jackson.WinkJacksonJaxbJsonProvider;
 import org.apache.wink.providers.json.JSONUtils;
 import org.apache.wink.providers.json.JsonProvider;
 import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
 import org.apache.wink.test.mock.MockRequestConstructor;
-import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
 import org.json.JSONObject;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.mock.web.MockHttpServletResponse;
@@ -48,7 +48,7 @@ public class JacksonJSON4JBattleTest ext
         // last one listed takes priority
         // (note: this test relies on consistent behavior in MockServletInvocationTest.getSingletons()
-- if this
         //  method re-orders the data return from here, test results may change)
-        return new Object[] {new JacksonJaxbJsonProvider(), new JsonProvider()};
+        return new Object[] { new WinkJacksonJaxbJsonProvider(), new JsonProvider(),};
     }
 
     @Path("/json4j")

Modified: incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonPOJOTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonPOJOTest.java?rev=1001822&r1=1001821&r2=1001822&view=diff
==============================================================================
--- incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonPOJOTest.java
(original)
+++ incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/JacksonPOJOTest.java
Mon Sep 27 17:21:16 2010
@@ -29,10 +29,10 @@ import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 
+import org.apache.wink.providers.jackson.WinkJacksonJaxbJsonProvider;
 import org.apache.wink.providers.json.JSONUtils;
 import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
 import org.apache.wink.test.mock.MockRequestConstructor;
-import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
 import org.json.JSONArray;
 import org.json.JSONObject;
 import org.springframework.mock.web.MockHttpServletRequest;
@@ -47,8 +47,7 @@ public class JacksonPOJOTest extends Moc
 
     @Override
     protected Object[] getSingletons() {
-        JacksonJsonProvider jacksonProvider = new JacksonJsonProvider();
-        return new Object[] {jacksonProvider};
+        return new Object[] {new WinkJacksonJaxbJsonProvider()};
     }
 
     @Path("/jackson/pojo")

Modified: incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/PolymorphicTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/PolymorphicTest.java?rev=1001822&r1=1001821&r2=1001822&view=diff
==============================================================================
--- incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/PolymorphicTest.java
(original)
+++ incubator/wink/trunk/wink-providers/wink-jackson-provider/src/test/java/org/apache/wink/providers/jackson/internal/PolymorphicTest.java
Mon Sep 27 17:21:16 2010
@@ -29,6 +29,7 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 
+import org.apache.wink.providers.jackson.WinkJacksonJaxbJsonProvider;
 import org.apache.wink.providers.jackson.internal.jaxb.polymorphic.MyJAXBObject;
 import org.apache.wink.providers.jackson.internal.jaxb.polymorphic.MyProperties;
 import org.apache.wink.providers.jackson.internal.pojo.polymorphic.Animal;
@@ -45,7 +46,7 @@ import org.springframework.mock.web.Mock
 
 public class PolymorphicTest extends MockServletInvocationTest {
 
-    JacksonJsonProvider jacksonProvider;
+    WinkJacksonJaxbJsonProvider winkJacksonProvider = new WinkJacksonJaxbJsonProvider();
     
     @Override
     protected Class<?>[] getClasses() {
@@ -54,7 +55,7 @@ public class PolymorphicTest extends Moc
 
     @Override
     protected Object[] getSingletons() {
-        return new Object[]{new JacksonJsonProvider(), new JacksonJaxbJsonProvider()};
+        return new Object[] {winkJacksonProvider};
     }
 
     @Path("/test/myproperties")
@@ -99,7 +100,7 @@ public class PolymorphicTest extends Moc
         
         // call the provider as though the wink-client was in use on the client side
         InputStream is = new ByteArrayInputStream(response.getContentAsByteArray());
-        MyJAXBObject myJAXBObject = (MyJAXBObject)new JacksonJaxbJsonProvider().readFrom(Object.class,
MyJAXBObject.class, null, MediaType.APPLICATION_JSON_TYPE, null, is);
+        MyJAXBObject myJAXBObject = (MyJAXBObject)winkJacksonProvider.readFrom(Object.class,
MyJAXBObject.class, null, MediaType.APPLICATION_JSON_TYPE, null, is);
 
         // make sure the Jackson deserializer is using the 'type' property on the XmlElement
annotation in MyJAXBObject
         // confirm Jackson deserialized to expected object type -- support for this was added
in Jackson 1.4



Mime
View raw message