Skip to content

Commit

Permalink
Upgraded to Jackson 2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Winterfeldt committed Sep 11, 2013
1 parent f372ad9 commit 2de6b40
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 134 deletions.
20 changes: 12 additions & 8 deletions app/contact-app/contact-rest-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>

<dependency>
<groupId>org.springbyexample</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2007-2012 the original author or authors.
* Copyright 2007-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,25 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springbyexample.web.servlet.mvc.json;

import java.util.Collection;

import org.codehaus.jackson.annotate.JsonTypeInfo;
import org.codehaus.jackson.map.BeanProperty;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.SerializationConfig;
import org.codehaus.jackson.map.TypeDeserializer;
import org.codehaus.jackson.map.TypeSerializer;
import org.codehaus.jackson.map.jsontype.NamedType;
import org.codehaus.jackson.map.jsontype.impl.StdTypeResolverBuilder;
import org.codehaus.jackson.type.JavaType;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;


/**
* Jackson type resolver that includes class names for certain classes.
*
*
* @author David Winterfeldt
*/
public class ClassTypeResolverBuilder extends StdTypeResolverBuilder {
Expand All @@ -43,24 +41,24 @@ public ClassTypeResolverBuilder() {
inclusion(JsonTypeInfo.As.PROPERTY);
typeProperty(CLASS_TYPE_PROPERTY);
}

@Override
public TypeDeserializer buildTypeDeserializer(DeserializationConfig config, JavaType baseType,
Collection<NamedType> subtypes, BeanProperty property) {
return (isSupportedJsonClassType(baseType) ? super.buildTypeDeserializer(config, baseType, subtypes, property) : null);
Collection<NamedType> subtypes) {
return (isSupportedJsonClassType(baseType) ? super.buildTypeDeserializer(config, baseType, subtypes) : null);
}

@Override
public TypeSerializer buildTypeSerializer(SerializationConfig config, JavaType baseType,
Collection<NamedType> subtypes, BeanProperty property) {
return (isSupportedJsonClassType(baseType) ? super.buildTypeSerializer(config, baseType, subtypes, property) : null);
Collection<NamedType> subtypes) {
return (isSupportedJsonClassType(baseType) ? super.buildTypeSerializer(config, baseType, subtypes) : null);
}

/**
* Checks if the class type should be used.
*/
private boolean isSupportedJsonClassType(JavaType baseType) {
if (baseType.isArrayType() ||
private boolean isSupportedJsonClassType(JavaType baseType) {
if (baseType.isArrayType() ||
baseType.isCollectionLikeType() || baseType.isMapLikeType() ||
java.util.Date.class.isAssignableFrom(baseType.getRawClass())) {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2007-2012 the original author or authors.
* Copyright 2007-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,23 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springbyexample.web.servlet.mvc.json;

import java.text.SimpleDateFormat;

import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import com.fasterxml.jackson.databind.ObjectMapper;


/**
* Jackson type resolver that includes class names for certain classes.
*
*
* @author David Winterfeldt
*/
public class RestObjectMapper extends ObjectMapper {

// "December 19, 1989 03:24:00"
public static final String PATTERN = "MMM dd, yyyy HH:mm:ss";

Expand All @@ -38,12 +33,12 @@ public RestObjectMapper() {

// this.getDeserializerProvider().withAdditionalDeserializers(new JodaDeserializers.DateTimeDeserializer<ReadableInstant>(DateTime.class));
// super.add addDeserializer(new JodaDeserializers());

// SerializationConfig serConfig = getSerializationConfig();
// serConfig.setDateFormat(new SimpleDateFormat(PATTERN));
// DeserializationConfig deserializationConfig = getDeserializationConfig();
// deserializationConfig.setDateFormat(new SimpleDateFormat(PATTERN));
// configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@

<beans profile="rest-json">
<import resource="classpath:/META-INF/spring/mvc/rest-json-converter-context.xml"/>
<import resource="classpath:/META-INF/spring/mvc/rest-json-type-converter-context.xml"/>

<!-- since id is the same as XML list above, essentially overriding the other list -->
<util:list id="messageConvertersList">
<ref bean="mappingJacksonHttpMessageConverter"/>
<ref bean="mappingJacksonHttpMessageConverterWithType"/>
</util:list>
</beans>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,30 @@
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">

<bean id="abstractJacksonObjectMapper"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"
abstract="true"
p:targetMethod="disable">

<bean id="abstractJacksonObjectMapper" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"
p:targetMethod="registerModule">
<property name="targetObject">
<bean class="org.codehaus.jackson.map.ObjectMapper" />
<bean class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean"
p:indentOutput="true" p:simpleDateFormat="yyyy-MM-dd'T'HH:mm:ss.SSSZ">
<property name="featuresToDisable">
<util:constant static-field="com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES" />
</property>
</bean>
</property>
<property name="arguments">
<list>
<util:constant static-field="org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES"/>
<bean class="com.fasterxml.jackson.datatype.joda.JodaModule" />
</list>
</property>
</bean>
</bean>

<bean id="abstractMappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"
abstract="true"/>

<bean id="abstractMappingJacksonJsonView"
class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"
class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"
abstract="true"
p:extractValueFromSingleKeyModel="true"/>

Expand Down
16 changes: 8 additions & 8 deletions enterprise/spring-rest-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
<artifactId>spring-webmvc</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</dependency>

<dependency>
<groupId>org.mortbay.jetty</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
<bean id="jacksonObjectMapper" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"
p:targetMethod="disable">
<property name="targetObject">
<bean class="org.codehaus.jackson.map.ObjectMapper"/>
<bean class="com.fasterxml.jackson.databind.ObjectMapper"/>
</property>
<property name="arguments">
<list>
<util:constant static-field="org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES"/>
<util:constant static-field="com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES"/>
</list>
</property>
</bean>

<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"
p:supportedMediaTypes="application/json"
p:objectMapper-ref="jacksonObjectMapper"/>

<bean id="mappingJacksonJsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"
<bean id="mappingJacksonJsonView" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"
p:extractValueFromSingleKeyModel="true"
p:objectMapper-ref="jacksonObjectMapper"/>

Expand Down
8 changes: 0 additions & 8 deletions modules/sbe-rest/sbe-rest-core-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</dependency>

<dependency>
<groupId>org.mortbay.jetty</groupId>
Expand Down
20 changes: 12 additions & 8 deletions modules/sbe-rest/sbe-rest-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@
<artifactId>spring-webmvc</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand All @@ -62,14 +74,6 @@
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</dependency>

<dependency>
<groupId>org.mortbay.jetty</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2007-2012 the original author or authors.
* Copyright 2007-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,25 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springbyexample.mvc.json;

import java.util.Collection;

import org.codehaus.jackson.annotate.JsonTypeInfo;
import org.codehaus.jackson.map.BeanProperty;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.SerializationConfig;
import org.codehaus.jackson.map.TypeDeserializer;
import org.codehaus.jackson.map.TypeSerializer;
import org.codehaus.jackson.map.jsontype.NamedType;
import org.codehaus.jackson.map.jsontype.impl.StdTypeResolverBuilder;
import org.codehaus.jackson.type.JavaType;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;


/**
* Jackson type resolver that includes class names for certain classes.
*
*
* @author David Winterfeldt
*/
public class ClassTypeResolverBuilder extends StdTypeResolverBuilder {
Expand All @@ -43,24 +41,24 @@ public ClassTypeResolverBuilder() {
inclusion(JsonTypeInfo.As.PROPERTY);
typeProperty(CLASS_TYPE_PROPERTY);
}

@Override
public TypeDeserializer buildTypeDeserializer(DeserializationConfig config, JavaType baseType,
Collection<NamedType> subtypes, BeanProperty property) {
return (isSupportedJsonClassType(baseType) ? super.buildTypeDeserializer(config, baseType, subtypes, property) : null);
Collection<NamedType> subtypes) {
return (isSupportedJsonClassType(baseType) ? super.buildTypeDeserializer(config, baseType, subtypes) : null);
}

@Override
public TypeSerializer buildTypeSerializer(SerializationConfig config, JavaType baseType,
Collection<NamedType> subtypes, BeanProperty property) {
return (isSupportedJsonClassType(baseType) ? super.buildTypeSerializer(config, baseType, subtypes, property) : null);
Collection<NamedType> subtypes) {
return (isSupportedJsonClassType(baseType) ? super.buildTypeSerializer(config, baseType, subtypes) : null);
}

/**
* Checks if the class type should be used.
*/
private boolean isSupportedJsonClassType(JavaType baseType) {
if (baseType.isArrayType() ||
private boolean isSupportedJsonClassType(JavaType baseType) {
if (baseType.isArrayType() ||
baseType.isCollectionLikeType() || baseType.isMapLikeType() ||
java.util.Date.class.isAssignableFrom(baseType.getRawClass())) {
return false;
Expand Down
Loading

0 comments on commit 2de6b40

Please sign in to comment.