Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ organization := "com.fasterxml.jackson.module"

scalaVersion := "2.11.7"

crossScalaVersions := Seq("2.10.5", "2.11.7")
crossScalaVersions := Seq("2.10.6", "2.11.7")

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

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

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

libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"com.fasterxml.jackson.core" % "jackson-core" % "2.6.3",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.6.3",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.6.3",
"com.fasterxml.jackson.module" % "jackson-module-paranamer" % "2.6.3",
"com.fasterxml.jackson.core" % "jackson-core" % "2.7.2",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.7.2",
"com.fasterxml.jackson.core" % "jackson-databind" % "2.7.2",
"com.fasterxml.jackson.module" % "jackson-module-paranamer" % "2.7.2",
// test dependencies
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.6.3" % "test",
"com.fasterxml.jackson.datatype" % "jackson-datatype-guava" % "2.6.3" % "test",
"com.fasterxml.jackson.module" % "jackson-module-jsonSchema" % "2.6.3" % "test",
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.7.2" % "test",
"com.fasterxml.jackson.datatype" % "jackson-datatype-guava" % "2.7.2" % "test",
"com.fasterxml.jackson.module" % "jackson-module-jsonSchema" % "2.7.2" % "test",
"org.scalatest" %% "scalatest" % "2.2.1" % "test",
"junit" % "junit" % "4.11" % "test"
)
Expand Down
1 change: 0 additions & 1 deletion project/build.properties

This file was deleted.

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

initializers result() foreach (_ apply context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private class OptionDeserializer(elementType: JavaType,
p <- Option(property)
intr <- Option(ctxt.getAnnotationIntrospector)
} yield {
intr.findDeserializationContentType(p.getMember, p.getType)
intr.refineDeserializationType(ctxt.getConfig, p.getMember, p.getType)
}).isDefined

override def deserialize(jp: JsonParser, ctxt: DeserializationContext) = valueTypeDeser match {
Expand Down Expand Up @@ -73,7 +73,7 @@ private object OptionDeserializerResolver extends Deserializers.Base {
elementValueDeserializer: JsonDeserializer[_]) =
if (!OPTION.isAssignableFrom(theType.getRawClass)) null
else {
val elementType = theType.containedType(0)
val elementType = theType.getContentType
val typeDeser = Option(elementTypeDeserializer).orElse(Option(elementType.getTypeHandler.asInstanceOf[TypeDeserializer]))
val valDeser: Option[JsonDeserializer[_]] = Option(elementValueDeserializer).orElse(Option(elementType.getValueHandler))
new OptionDeserializer(elementType, typeDeser, None, valDeser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ private class BuilderWrapper[E](val builder: mutable.Builder[E, _ <: Iterable[E]
}

private object SeqDeserializer {
val COMPANIONS = new CompanionSorter[collection.Seq]()
val COMPANIONS = new CompanionSorter[collection.Iterable]()
.add(IndexedSeq)
.add(mutable.ArraySeq)
.add(mutable.Buffer)
.add(mutable.IndexedSeq)
.add(mutable.LinearSeq)
.add(mutable.ListBuffer)
.add(mutable.Iterable)
.add(mutable.MutableList)
.add(mutable.Queue)
.add(mutable.ResizableArray)
.add(mutable.Seq)
.add(Queue)
.add(Stream)
.toList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ private class SortedMapDeserializer(
with ContextualDeserializer {

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

private val instantiator =
new ValueInstantiator {
def getValueTypeDesc = collectionType.getRawClass.getCanonicalName
override def canCreateUsingDefault = true
override def createUsingDefault(ctx: DeserializationContext) =
new SortedMapBuilderWrapper[AnyRef,AnyRef](SortedMapDeserializer.builderFor(collectionType.getRawClass, collectionType.containedType(0)))
new SortedMapBuilderWrapper[AnyRef,AnyRef](SortedMapDeserializer.builderFor(collectionType.getRawClass, collectionType.getKeyType))
}

private val containerDeserializer =
Expand Down Expand Up @@ -85,7 +85,6 @@ private object SortedMapDeserializerResolver extends Deserializers.Base {
elementDeserializer: JsonDeserializer[_]): JsonDeserializer[_] =
if (!SORTED_MAP.isAssignableFrom(theType.getRawClass)) null
else new SortedMapDeserializer(theType,config,keyDeserializer,elementDeserializer,elementTypeDeserializer)

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private object SortedSetDeserializerResolver extends Deserializers.Base {
if (!SORTED_SET.isAssignableFrom(rawClass)) null
else {
val deser = elementDeserializer.asInstanceOf[JsonDeserializer[AnyRef]]
val instantiator = new SortedSetInstantiator(config, rawClass, collectionType.containedType(0))
val instantiator = new SortedSetInstantiator(config, rawClass, collectionType.getContentType)
new SortedSetDeserializer(collectionType, deser, elementTypeDeserializer, instantiator)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private class UnsortedMapDeserializer(
with ContextualDeserializer {

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

private val instantiator =
new ValueInstantiator {
Expand All @@ -73,7 +73,7 @@ private class UnsortedMapDeserializer(
}

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

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.{util => ju}

import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.core.`type`.TypeReference
import com.fasterxml.jackson.databind.`type`.{CollectionType, MapType}
import com.fasterxml.jackson.databind.deser.{Deserializers, std}
import com.fasterxml.jackson.databind.{BeanDescription, DeserializationConfig, DeserializationContext, DeserializationFeature, JavaType, JsonDeserializer}
import com.fasterxml.jackson.module.scala.JacksonModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object OrderingLocator {
val ordering =
found.getOrElse {
if (matches(classOf[Option[_]])) {
val delegate = locate(javaType.containedType(0))
val delegate = locate(javaType.getContentType)
Ordering.Option(delegate)
}
else if (matches(classOf[Comparable[_]]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object ScalaAnnotationIntrospector extends NopAnnotationIntrospector
private def isScala(a: Annotated): Boolean = {
a match {
case ac: AnnotatedClass => isMaybeScalaBeanType(ac.getAnnotated)
case am: AnnotatedMember => isMaybeScalaBeanType(am.getContextClass.getAnnotated)
case am: AnnotatedMember => isMaybeScalaBeanType(am.getDeclaringClass)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package com.fasterxml.jackson.module.scala.modifiers
import java.lang.reflect.Type

import com.fasterxml.jackson.databind.JavaType
import com.fasterxml.jackson.databind.`type`.{TypeBindings, TypeFactory, TypeModifier}
import com.fasterxml.jackson.databind.`type`.{CollectionLikeType, TypeBindings, TypeFactory, TypeModifier}

private [modifiers] trait CollectionLikeTypeModifier extends TypeModifier with GenTypeModifier {

def BASE: Class[_]

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ package com.fasterxml.jackson.module.scala.modifiers

import java.lang.reflect.Type

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.`type`.{TypeBindings, TypeFactory, TypeModifier};
import com.fasterxml.jackson.databind.JavaType
import com.fasterxml.jackson.databind.`type`.{MapLikeType, TypeBindings, TypeFactory, TypeModifier}

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

private object MapTypeModifer extends TypeModifier with GenTypeModifier {

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

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

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private class EitherSerializer(elementType: Option[JavaType],
}
def hasContentTypeAnnotation(provider: SerializerProvider, property: BeanProperty) =
Option(property).exists { p =>
Option(provider.getAnnotationIntrospector.findSerializationContentType(p.getMember, p.getType)).isDefined
Option(provider.getAnnotationIntrospector.refineSerializationType(provider.getConfig, p.getMember, p.getType)).isDefined
}

def tryContentSerializer(serializerProvider: SerializerProvider, property: BeanProperty, currentSer: Option[JsonSerializer[_]]) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private object ScalaIteratorSerializerResolver extends Serializers.Base {

val rawClass = collectionType.getRawClass
if (!classOf[collection.Iterator[Any]].isAssignableFrom(rawClass)) null else
new UnresolvedIteratorSerializer(rawClass, collectionType.containedType(0), false, elementTypeSerializer, elementSerializer)
new UnresolvedIteratorSerializer(rawClass, collectionType.getContentType, false, elementTypeSerializer, elementSerializer)
}
}

Expand Down
Loading