Skip to content

Commit 5b36c6b

Browse files
Drop guava
1 parent b04952a commit 5b36c6b

File tree

7 files changed

+52
-82
lines changed

7 files changed

+52
-82
lines changed

build.sbt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ libraryDependencies ++= Seq(
2323
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.5.0",
2424
"com.fasterxml.jackson.core" % "jackson-databind" % "2.5.0",
2525
"com.thoughtworks.paranamer" % "paranamer" % "2.6",
26-
"com.google.code.findbugs" % "jsr305" % "2.0.1",
27-
"com.google.guava" % "guava" % "18.0",
2826
// test dependencies
2927
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.5.0" % "test",
3028
"com.fasterxml.jackson.datatype" % "jackson-datatype-guava" % "2.5.0" % "test",

src/main/scala/com/fasterxml/jackson/module/scala/experimental/ScalaObjectMapper.scala

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import com.fasterxml.jackson.core._
77
import com.fasterxml.jackson.databind._
88
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper
99
import com.fasterxml.jackson.databind.jsonschema.JsonSchema
10-
import com.fasterxml.jackson.module.scala.util.Implicits._
11-
import com.google.common.cache.{CacheBuilder, LoadingCache}
1210

1311
trait ScalaObjectMapper {
1412
self: ObjectMapper =>
@@ -55,32 +53,30 @@ trait ScalaObjectMapper {
5553
* type (typically <code>java.lang.Class</code>), but without explicit
5654
* context.
5755
*/
58-
private[this] val typeCache: LoadingCache[Manifest[_], JavaType] =
59-
CacheBuilder.newBuilder().maximumSize(DEFAULT_CACHE_SIZE).build { m: Manifest[_] =>
60-
val clazz = m.runtimeClass
61-
if(isArray(clazz)) {
62-
//It looks like getting the component type is the best we can do, at
63-
//least if we also want to support 2.9.x - scala 2.10.x adds full
64-
//type info in the typeArguments field of an Array's manifest.
65-
getTypeFactory.constructArrayType(clazz.getComponentType)
66-
} else if(isMapLike(clazz)) {
67-
val typeArguments = m.typeArguments.map(constructType(_)).toArray
68-
if(typeArguments.length != 2) {
69-
throw new IllegalArgumentException("Need exactly 2 type parameters for map like types ("+clazz.getName+")")
70-
}
71-
getTypeFactory.constructMapLikeType(clazz, typeArguments(0), typeArguments(1))
72-
} else if(isCollectionLike(clazz)) {
73-
val typeArguments = m.typeArguments.map(constructType(_)).toArray
74-
if(typeArguments.length != 1) {
75-
throw new IllegalArgumentException("Need exactly 1 type parameter for collection like types ("+clazz.getName+")")
76-
}
77-
getTypeFactory.constructCollectionLikeType(clazz, typeArguments(0))
78-
} else {
79-
val typeArguments = m.typeArguments.map(constructType(_)).toArray
80-
getTypeFactory.constructParametrizedType(clazz, clazz, typeArguments: _*)
56+
def constructType[T](implicit m: Manifest[T]): JavaType = {
57+
val clazz = m.runtimeClass
58+
if(isArray(clazz)) {
59+
//It looks like getting the component type is the best we can do, at
60+
//least if we also want to support 2.9.x - scala 2.10.x adds full
61+
//type info in the typeArguments field of an Array's manifest.
62+
getTypeFactory.constructArrayType(clazz.getComponentType)
63+
} else if(isMapLike(clazz)) {
64+
val typeArguments = m.typeArguments.map(constructType(_)).toArray
65+
if(typeArguments.length != 2) {
66+
throw new IllegalArgumentException("Need exactly 2 type parameters for map like types ("+clazz.getName+")")
8167
}
68+
getTypeFactory.constructMapLikeType(clazz, typeArguments(0), typeArguments(1))
69+
} else if(isCollectionLike(clazz)) {
70+
val typeArguments = m.typeArguments.map(constructType(_)).toArray
71+
if(typeArguments.length != 1) {
72+
throw new IllegalArgumentException("Need exactly 1 type parameter for collection like types ("+clazz.getName+")")
73+
}
74+
getTypeFactory.constructCollectionLikeType(clazz, typeArguments(0))
75+
} else {
76+
val typeArguments = m.typeArguments.map(constructType(_)).toArray
77+
getTypeFactory.constructParametrizedType(clazz, clazz, typeArguments: _*)
8278
}
83-
def constructType[T](implicit m: Manifest[T]): JavaType = typeCache.get(m)
79+
}
8480

8581
/*
8682
**********************************************************

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323

2424
package com.fasterxml.jackson.module.scala.introspect
2525

26-
import com.thoughtworks.paranamer.BytecodeReadingParanamer
27-
import scala.reflect.NameTransformer
28-
import java.lang.reflect.{Modifier, Field, Constructor, Method}
29-
import com.google.common.cache.{LoadingCache, CacheBuilder}
26+
import java.lang.reflect.{Constructor, Field, Method, Modifier}
27+
28+
import com.thoughtworks.paranamer.{BytecodeReadingParanamer, CachingParanamer}
29+
3030
import scala.annotation.tailrec
31-
import com.fasterxml.jackson.module.scala.util.Implicits._
31+
import scala.reflect.NameTransformer
3232

3333
//TODO: This might be more efficient/type safe if we used Scala reflection here
3434
//but we have to support 2.9.x and 2.10.x - once the scala reflection APIs
@@ -37,22 +37,10 @@ import com.fasterxml.jackson.module.scala.util.Implicits._
3737

3838
object BeanIntrospector {
3939

40-
private [this] val paranamer = new BytecodeReadingParanamer
41-
private [this] val ctorParamNamesCache: LoadingCache[Constructor[_],Array[String]] =
42-
// TODO: consider module configuration of the cache
43-
CacheBuilder.newBuilder
44-
.maximumSize(DEFAULT_CACHE_SIZE)
45-
.build(paranamer.lookupParameterNames(_: Constructor[_]).map(NameTransformer.decode))
40+
private [this] val paranamer = new CachingParanamer(new BytecodeReadingParanamer)
4641

4742
private def getCtorParams(ctor: Constructor[_]): Array[String] =
48-
try
49-
{
50-
ctorParamNamesCache.get(ctor)
51-
}
52-
catch
53-
{
54-
case _: Exception => Array.empty
55-
}
43+
paranamer.lookupParameterNames(ctor, false).map(NameTransformer.decode)
5644

5745
def apply[T <: AnyRef](implicit mf: Manifest[_]): BeanDescriptor = apply[T](mf.runtimeClass)
5846

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,43 @@ package introspect
33

44
import com.fasterxml.jackson.annotation.JsonCreator
55
import com.fasterxml.jackson.databind.PropertyName
6+
import com.fasterxml.jackson.databind.`type`.ClassKey
67
import com.fasterxml.jackson.databind.introspect._
8+
import com.fasterxml.jackson.databind.util.LRUMap
79
import com.fasterxml.jackson.module.scala.util.Implicits._
8-
import com.google.common.cache.{CacheBuilder, LoadingCache}
910

1011
import scala.collection.JavaConverters._
1112

1213
object ScalaAnnotationIntrospector extends JacksonAnnotationIntrospector
1314
{
14-
val descriptors: LoadingCache[Class[_], BeanDescriptor] =
15-
CacheBuilder.newBuilder()
16-
.maximumSize(DEFAULT_CACHE_SIZE)
17-
.build(BeanIntrospector.apply (_:Class[_]))
15+
private [this] val _descriptorCache = new LRUMap[ClassKey, BeanDescriptor](16, 100)
1816

19-
val classes: LoadingCache[Class[_], AnnotatedClass] =
20-
CacheBuilder.newBuilder()
21-
.maximumSize(DEFAULT_CACHE_SIZE)
22-
.build(AnnotatedClass.constructWithoutSuperTypes(_:Class[_], this, null))
17+
private def _descriptorFor(clz: Class[_]): BeanDescriptor = {
18+
val key = new ClassKey(clz)
19+
var result = _descriptorCache.get(key)
20+
if (result == null) {
21+
result = BeanIntrospector(clz)
22+
_descriptorCache.put(key, result)
23+
}
24+
25+
result
26+
}
2327

2428
private def annotatedClassFor(am: AnnotatedMember): AnnotatedClass =
25-
classes.get(am.getDeclaringClass)
29+
am.getContextClass
2630

2731
private def fieldName(af: AnnotatedField): Option[String] = {
28-
val d = descriptors.get(af.getDeclaringClass)
32+
val d = _descriptorFor(af.getDeclaringClass)
2933
d.properties.find(p => p.field.exists(_ == af.getAnnotated)).map(_.name)
3034
}
3135

3236
private def methodName(am: AnnotatedMethod): Option[String] = {
33-
val d = descriptors.get(am.getDeclaringClass)
37+
val d = _descriptorFor(am.getDeclaringClass)
3438
d.properties.find(p => (p.getter ++ p.setter).exists(_ == am.getAnnotated)).map(_.name)
3539
}
3640

3741
private def paramName(ap: AnnotatedParameter): Option[String] = {
38-
val d = descriptors.get(ap.getDeclaringClass)
42+
val d = _descriptorFor(ap.getDeclaringClass)
3943
d.properties.find(p => p.param.exists { cp =>
4044
cp.constructor == ap.getOwner.getAnnotated && cp.index == ap.getIndex
4145
}).map(_.name)
@@ -44,7 +48,7 @@ object ScalaAnnotationIntrospector extends JacksonAnnotationIntrospector
4448
private def paramFor(a: Annotated): Option[AnnotatedParameter] = {
4549
a match {
4650
case am: AnnotatedMember =>
47-
val d = descriptors.get(am.getDeclaringClass)
51+
val d = _descriptorFor(am.getDeclaringClass)
4852
val prop = d.properties.find(p =>
4953
(p.field ++ p.getter ++ p.setter ++ p.param).exists(_ == a.getAnnotated)
5054
)
@@ -72,7 +76,7 @@ object ScalaAnnotationIntrospector extends JacksonAnnotationIntrospector
7276
override def hasCreatorAnnotation(a: Annotated): Boolean = {
7377
a match {
7478
case ac: AnnotatedConstructor =>
75-
val d = descriptors.get(ac.getDeclaringClass)
79+
val d = _descriptorFor(ac.getDeclaringClass)
7680
d.properties.exists(p => p.param.exists(_.constructor == ac.getAnnotated))
7781
case _ => false
7882
}

src/main/scala/com/fasterxml/jackson/module/scala/util/CacheLoaders.scala

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.fasterxml.jackson.module.scala.util
22

33
object Implicits
4-
extends CacheLoaders
5-
with Classes
4+
extends Classes
65
with Options
76
with Strings

src/test/scala/com/fasterxml/jackson/module/scala/ser/NamingStrategyTest.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ package module.scala
33
package ser
44

55
import java.io.ByteArrayOutputStream
6-
import javax.annotation.Nonnull
7-
8-
import databind.{ObjectMapper, PropertyNamingStrategy}
96

7+
import com.fasterxml.jackson.databind.{ObjectMapper, PropertyNamingStrategy}
108
import com.google.common.base.Optional
119
import org.junit.runner.RunWith
1210
import org.scalatest.junit.JUnitRunner
@@ -15,8 +13,8 @@ import org.scalatest.{Matchers, Outcome, fixture}
1513
import scala.beans.BeanProperty
1614

1715
class PojoWrittenInScala {
18-
@Nonnull @BeanProperty var optFoo: Optional[String] = Optional.absent()
19-
@Nonnull @BeanProperty var bar: Int = 0
16+
@BeanProperty var optFoo: Optional[String] = Optional.absent()
17+
@BeanProperty var bar: Int = 0
2018
}
2119

2220
@RunWith(classOf[JUnitRunner])

0 commit comments

Comments
 (0)