Skip to content

Commit d386b7f

Browse files
committed
Upgrade to Jackson 2.7 branch. All current tests pass.
1 parent 978a2f5 commit d386b7f

25 files changed

+111
-100
lines changed

build.sbt

+10-9
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ organization := "com.fasterxml.jackson.module"
77

88
scalaVersion := "2.11.7"
99

10-
crossScalaVersions := Seq("2.10.5", "2.11.7")
10+
crossScalaVersions := Seq("2.10.6", "2.11.7")
1111

1212
scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature")
1313

14-
scalacOptions in (Compile, compile) += "-Xfatal-warnings"
14+
// Temporarily disable warnings as fatal until migrate Option to new features.
15+
//scalacOptions in (Compile, compile) += "-Xfatal-warnings"
1516

1617
// Ensure jvm 1.6 for java
1718
lazy val java6Home = new File(System.getenv("JAVA6_HOME"))
@@ -27,14 +28,14 @@ scalacOptions += "-target:jvm-1.6"
2728

2829
libraryDependencies ++= Seq(
2930
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
30-
"com.fasterxml.jackson.core" % "jackson-core" % "2.6.3",
31-
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.6.3",
32-
"com.fasterxml.jackson.core" % "jackson-databind" % "2.6.3",
33-
"com.fasterxml.jackson.module" % "jackson-module-paranamer" % "2.6.3",
31+
"com.fasterxml.jackson.core" % "jackson-core" % "2.7.2",
32+
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.7.2",
33+
"com.fasterxml.jackson.core" % "jackson-databind" % "2.7.2",
34+
"com.fasterxml.jackson.module" % "jackson-module-paranamer" % "2.7.2",
3435
// test dependencies
35-
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.6.3" % "test",
36-
"com.fasterxml.jackson.datatype" % "jackson-datatype-guava" % "2.6.3" % "test",
37-
"com.fasterxml.jackson.module" % "jackson-module-jsonSchema" % "2.6.3" % "test",
36+
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.7.2" % "test",
37+
"com.fasterxml.jackson.datatype" % "jackson-datatype-guava" % "2.7.2" % "test",
38+
"com.fasterxml.jackson.module" % "jackson-module-jsonSchema" % "2.7.2" % "test",
3839
"org.scalatest" %% "scalatest" % "2.2.1" % "test",
3940
"junit" % "junit" % "4.11" % "test"
4041
)

project/build.properties

-1
This file was deleted.

src/main/scala/com/fasterxml/jackson/module/scala/JacksonModule.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ trait JacksonModule extends Module {
5353
val MinorVersion = version.getMinorVersion
5454
context.getMapperVersion match {
5555
case version@VersionExtractor(MajorVersion, minor) if minor < MinorVersion =>
56-
throw new JsonMappingException("Jackson version is too old " + version)
56+
throw new JsonMappingException(null, "Jackson version is too old " + version)
5757
case version@VersionExtractor(MajorVersion, minor) =>
5858
// Under semantic versioning, this check would not be needed; however Jackson
5959
// occasionally has functionally breaking changes across minor versions
6060
// (2.4 -> 2.5 as an example). This may be the fault of the Scala module
6161
// depending on implementation details, so for now we'll just declare ourselves
6262
// as incompatible and move on.
6363
if (minor > MinorVersion) {
64-
throw new JsonMappingException("Incompatible Jackson version: " + version)
64+
throw new JsonMappingException(null, "Incompatible Jackson version: " + version)
6565
}
6666
case version =>
67-
throw new JsonMappingException("Incompatible Jackson version: " + version)
67+
throw new JsonMappingException(null, "Incompatible Jackson version: " + version)
6868
}
6969

7070
initializers result() foreach (_ apply context)

src/main/scala/com/fasterxml/jackson/module/scala/deser/OptionDeserializerModule.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private class OptionDeserializer(elementType: JavaType,
4141
p <- Option(property)
4242
intr <- Option(ctxt.getAnnotationIntrospector)
4343
} yield {
44-
intr.findDeserializationContentType(p.getMember, p.getType)
44+
intr.refineDeserializationType(ctxt.getConfig, p.getMember, p.getType)
4545
}).isDefined
4646

4747
override def deserialize(jp: JsonParser, ctxt: DeserializationContext) = valueTypeDeser match {
@@ -73,7 +73,7 @@ private object OptionDeserializerResolver extends Deserializers.Base {
7373
elementValueDeserializer: JsonDeserializer[_]) =
7474
if (!OPTION.isAssignableFrom(theType.getRawClass)) null
7575
else {
76-
val elementType = theType.containedType(0)
76+
val elementType = theType.getContentType
7777
val typeDeser = Option(elementTypeDeserializer).orElse(Option(elementType.getTypeHandler.asInstanceOf[TypeDeserializer]))
7878
val valDeser: Option[JsonDeserializer[_]] = Option(elementValueDeserializer).orElse(Option(elementType.getValueHandler))
7979
new OptionDeserializer(elementType, typeDeser, None, valDeser)

src/main/scala/com/fasterxml/jackson/module/scala/deser/SeqDeserializerModule.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ private class BuilderWrapper[E](val builder: mutable.Builder[E, _ <: Iterable[E]
2727
}
2828

2929
private object SeqDeserializer {
30-
val COMPANIONS = new CompanionSorter[collection.Seq]()
30+
val COMPANIONS = new CompanionSorter[collection.Iterable]()
3131
.add(IndexedSeq)
3232
.add(mutable.ArraySeq)
3333
.add(mutable.Buffer)
3434
.add(mutable.IndexedSeq)
3535
.add(mutable.LinearSeq)
3636
.add(mutable.ListBuffer)
37+
.add(mutable.Iterable)
3738
.add(mutable.MutableList)
3839
.add(mutable.Queue)
3940
.add(mutable.ResizableArray)
41+
.add(mutable.Seq)
4042
.add(Queue)
4143
.add(Stream)
4244
.toList

src/main/scala/com/fasterxml/jackson/module/scala/deser/SortedMapDeserializerModule.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ private class SortedMapDeserializer(
4141
with ContextualDeserializer {
4242

4343
private val javaContainerType =
44-
config.getTypeFactory.constructMapLikeType(classOf[MapBuilderWrapper[_,_]], collectionType.containedType(0), collectionType.containedType(1))
44+
config.getTypeFactory.constructMapLikeType(classOf[MapBuilderWrapper[_,_]], collectionType.getKeyType, collectionType.getContentType)
4545

4646
private val instantiator =
4747
new ValueInstantiator {
4848
def getValueTypeDesc = collectionType.getRawClass.getCanonicalName
4949
override def canCreateUsingDefault = true
5050
override def createUsingDefault(ctx: DeserializationContext) =
51-
new SortedMapBuilderWrapper[AnyRef,AnyRef](SortedMapDeserializer.builderFor(collectionType.getRawClass, collectionType.containedType(0)))
51+
new SortedMapBuilderWrapper[AnyRef,AnyRef](SortedMapDeserializer.builderFor(collectionType.getRawClass, collectionType.getKeyType))
5252
}
5353

5454
private val containerDeserializer =
@@ -85,7 +85,6 @@ private object SortedMapDeserializerResolver extends Deserializers.Base {
8585
elementDeserializer: JsonDeserializer[_]): JsonDeserializer[_] =
8686
if (!SORTED_MAP.isAssignableFrom(theType.getRawClass)) null
8787
else new SortedMapDeserializer(theType,config,keyDeserializer,elementDeserializer,elementTypeDeserializer)
88-
8988
}
9089

9190
/**

src/main/scala/com/fasterxml/jackson/module/scala/deser/SortedSetDeserializerModule.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private object SortedSetDeserializerResolver extends Deserializers.Base {
110110
if (!SORTED_SET.isAssignableFrom(rawClass)) null
111111
else {
112112
val deser = elementDeserializer.asInstanceOf[JsonDeserializer[AnyRef]]
113-
val instantiator = new SortedSetInstantiator(config, rawClass, collectionType.containedType(0))
113+
val instantiator = new SortedSetInstantiator(config, rawClass, collectionType.getContentType)
114114
new SortedSetDeserializer(collectionType, deser, elementTypeDeserializer, instantiator)
115115
}
116116
}

src/main/scala/com/fasterxml/jackson/module/scala/deser/UnsortedMapDeserializerModule.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private class UnsortedMapDeserializer(
4747
with ContextualDeserializer {
4848

4949
private val javaContainerType =
50-
config.getTypeFactory.constructMapLikeType(classOf[MapBuilderWrapper[_,_]], collectionType.containedType(0), collectionType.containedType(1))
50+
config.getTypeFactory.constructMapLikeType(classOf[MapBuilderWrapper[_,_]], collectionType.getKeyType, collectionType.getContentType)
5151

5252
private val instantiator =
5353
new ValueInstantiator {
@@ -73,7 +73,7 @@ private class UnsortedMapDeserializer(
7373
}
7474

7575
override def deserialize(jp: JsonParser, ctxt: DeserializationContext): GenMap[_,_] = {
76-
containerDeserializer.deserialize(jp,ctxt) match {
76+
containerDeserializer.deserialize(jp, ctxt) match {
7777
case wrapper: MapBuilderWrapper[_,_] => wrapper.builder.result()
7878
}
7979
}
@@ -96,7 +96,6 @@ private object UnsortedMapDeserializerResolver extends Deserializers.Base {
9696
else if (SORTED_MAP.isAssignableFrom(rawClass)) null
9797
else new UnsortedMapDeserializer(theType, config, keyDeserializer, elementDeserializer, elementTypeDeserializer)
9898
}
99-
10099
}
101100

102101
/**

src/main/scala/com/fasterxml/jackson/module/scala/deser/UntypedObjectDeserializerModule.scala

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.{util => ju}
44

55
import com.fasterxml.jackson.core.JsonParser
66
import com.fasterxml.jackson.core.`type`.TypeReference
7+
import com.fasterxml.jackson.databind.`type`.{CollectionType, MapType}
78
import com.fasterxml.jackson.databind.deser.{Deserializers, std}
89
import com.fasterxml.jackson.databind.{BeanDescription, DeserializationConfig, DeserializationContext, DeserializationFeature, JavaType, JsonDeserializer}
910
import com.fasterxml.jackson.module.scala.JacksonModule

src/main/scala/com/fasterxml/jackson/module/scala/introspect/OrderingLocator.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object OrderingLocator {
2424
val ordering =
2525
found.getOrElse {
2626
if (matches(classOf[Option[_]])) {
27-
val delegate = locate(javaType.containedType(0))
27+
val delegate = locate(javaType.getContentType)
2828
Ordering.Option(delegate)
2929
}
3030
else if (matches(classOf[Comparable[_]]))

src/main/scala/com/fasterxml/jackson/module/scala/introspect/ScalaAnnotationIntrospectorModule.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ object ScalaAnnotationIntrospector extends NopAnnotationIntrospector
5252
private def isScala(a: Annotated): Boolean = {
5353
a match {
5454
case ac: AnnotatedClass => isMaybeScalaBeanType(ac.getAnnotated)
55-
case am: AnnotatedMember => isMaybeScalaBeanType(am.getContextClass.getAnnotated)
55+
case am: AnnotatedMember => isMaybeScalaBeanType(am.getDeclaringClass)
5656
}
5757
}
5858

src/main/scala/com/fasterxml/jackson/module/scala/modifiers/CollectionLikeTypeModifier.scala

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ package com.fasterxml.jackson.module.scala.modifiers
33
import java.lang.reflect.Type
44

55
import com.fasterxml.jackson.databind.JavaType
6-
import com.fasterxml.jackson.databind.`type`.{TypeBindings, TypeFactory, TypeModifier}
6+
import com.fasterxml.jackson.databind.`type`.{CollectionLikeType, TypeBindings, TypeFactory, TypeModifier}
77

88
private [modifiers] trait CollectionLikeTypeModifier extends TypeModifier with GenTypeModifier {
99

1010
def BASE: Class[_]
1111

12-
override def modifyType(originalType: JavaType, jdkType: Type, context: TypeBindings, typeFactory: TypeFactory) =
13-
if (originalType.containedTypeCount() > 1) originalType else
14-
classObjectFor(jdkType) find BASE.isAssignableFrom map { cls =>
15-
val eltType = if (originalType.containedTypeCount() == 1) originalType.containedType(0) else UNKNOWN
16-
typeFactory.constructCollectionLikeType(cls, eltType)
17-
} getOrElse originalType
12+
override def modifyType(originalType: JavaType, jdkType: Type, context: TypeBindings, typeFactory: TypeFactory) = {
13+
if (classObjectFor(jdkType).exists(BASE.isAssignableFrom) && !originalType.isMapLikeType && originalType.containedTypeCount <= 1) {
14+
val valType = originalType.containedTypeOrUnknown(0)
15+
CollectionLikeType.upgradeFrom(originalType, valType)
16+
} else originalType
17+
}
1818

1919
}

src/main/scala/com/fasterxml/jackson/module/scala/modifiers/MapTypeModifierModule.scala

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ package com.fasterxml.jackson.module.scala.modifiers
22

33
import java.lang.reflect.Type
44

5-
import com.fasterxml.jackson.databind.JavaType;
6-
import com.fasterxml.jackson.databind.`type`.{TypeBindings, TypeFactory, TypeModifier};
5+
import com.fasterxml.jackson.databind.JavaType
6+
import com.fasterxml.jackson.databind.`type`.{MapLikeType, TypeBindings, TypeFactory, TypeModifier}
77

88
import com.fasterxml.jackson.module.scala.JacksonModule
99

1010
private object MapTypeModifer extends TypeModifier with GenTypeModifier {
1111

1212
val BASE = classOf[collection.Map[_,_]]
1313

14-
override def modifyType(originalType: JavaType, jdkType: Type, context: TypeBindings, typeFactory: TypeFactory) =
15-
classObjectFor(jdkType) find (BASE.isAssignableFrom(_)) map { cls =>
16-
val keyType = if (originalType.containedTypeCount() >= 1) originalType.containedType(0) else UNKNOWN
17-
val valueType = if (originalType.containedTypeCount() >= 2) originalType.containedType(1) else UNKNOWN
18-
typeFactory.constructMapLikeType(cls, keyType, valueType)
19-
} getOrElse originalType
14+
override def modifyType(originalType: JavaType, jdkType: Type, context: TypeBindings, typeFactory: TypeFactory) = {
15+
if (classObjectFor(jdkType).exists(BASE.isAssignableFrom)) {
16+
val keyType = originalType.containedTypeOrUnknown(0)
17+
val valueType = originalType.containedTypeOrUnknown(1)
18+
MapLikeType.upgradeFrom(originalType, keyType, valueType)
19+
} else originalType
20+
}
2021

2122
}
2223

src/main/scala/com/fasterxml/jackson/module/scala/ser/EitherSerializer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private class EitherSerializer(elementType: Option[JavaType],
5252
}
5353
def hasContentTypeAnnotation(provider: SerializerProvider, property: BeanProperty) =
5454
Option(property).exists { p =>
55-
Option(provider.getAnnotationIntrospector.findSerializationContentType(p.getMember, p.getType)).isDefined
55+
Option(provider.getAnnotationIntrospector.refineSerializationType(provider.getConfig, p.getMember, p.getType)).isDefined
5656
}
5757

5858
def tryContentSerializer(serializerProvider: SerializerProvider, property: BeanProperty, currentSer: Option[JsonSerializer[_]]) = {

src/main/scala/com/fasterxml/jackson/module/scala/ser/IteratorSerializerModule.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private object ScalaIteratorSerializerResolver extends Serializers.Base {
7474

7575
val rawClass = collectionType.getRawClass
7676
if (!classOf[collection.Iterator[Any]].isAssignableFrom(rawClass)) null else
77-
new UnresolvedIteratorSerializer(rawClass, collectionType.containedType(0), false, elementTypeSerializer, elementSerializer)
77+
new UnresolvedIteratorSerializer(rawClass, collectionType.getContentType, false, elementTypeSerializer, elementSerializer)
7878
}
7979
}
8080

0 commit comments

Comments
 (0)