This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merge pull request #60 from imikushin/jackson2

Jackson2
  • Loading branch information...
2 parents 7cffbe8 + b944379 commit 9b874e5bcbbff48f152328fcb256505d31309ad7 @codahale committed Jun 7, 2012
Showing with 253 additions and 293 deletions.
  1. +2 −2 .gitignore
  2. +5 −5 pom.xml
  3. +1 −1 src/main/java/com/codahale/jerkson/JsonSnakeCase.java
  4. +2 −2 src/main/scala/com/codahale/jerkson/Factory.scala
  5. +1 −1 src/main/scala/com/codahale/jerkson/Generator.scala
  6. +2 −2 src/main/scala/com/codahale/jerkson/Json.scala
  7. +3 −2 src/main/scala/com/codahale/jerkson/Parser.scala
  8. +2 −2 src/main/scala/com/codahale/jerkson/ParsingException.scala
  9. +5 −5 src/main/scala/com/codahale/jerkson/ScalaModule.scala
  10. +1 −1 src/main/scala/com/codahale/jerkson/StreamingIterator.scala
  11. +2 −2 src/main/scala/com/codahale/jerkson/Types.scala
  12. +4 −4 src/main/scala/com/codahale/jerkson/deser/BigDecimalDeserializer.scala
  13. +4 −4 src/main/scala/com/codahale/jerkson/deser/BigIntDeserializer.scala
  14. +4 −4 src/main/scala/com/codahale/jerkson/deser/BitSetDeserializer.scala
  15. +8 −9 src/main/scala/com/codahale/jerkson/deser/CaseClassDeserializer.scala
  16. +7 −9 src/main/scala/com/codahale/jerkson/deser/EitherDeserializer.scala
  17. +15 −9 src/main/scala/com/codahale/jerkson/deser/ImmutableMapDeserializer.scala
  18. +13 −7 src/main/scala/com/codahale/jerkson/deser/IntMapDeserializer.scala
  19. +15 −9 src/main/scala/com/codahale/jerkson/deser/IteratorDeserializer.scala
  20. +5 −5 src/main/scala/com/codahale/jerkson/deser/JValueDeserializer.scala
  21. +13 −7 src/main/scala/com/codahale/jerkson/deser/LongMapDeserializer.scala
  22. +13 −7 src/main/scala/com/codahale/jerkson/deser/MutableLinkedHashMapDeserializer.scala
  23. +0 −30 src/main/scala/com/codahale/jerkson/deser/MutableListDeserializer.scala
  24. +13 −7 src/main/scala/com/codahale/jerkson/deser/MutableMapDeserializer.scala
  25. +14 −8 src/main/scala/com/codahale/jerkson/deser/OptionDeserializer.scala
  26. +0 −30 src/main/scala/com/codahale/jerkson/deser/QueueDeserializer.scala
  27. +11 −10 src/main/scala/com/codahale/jerkson/deser/RangeDeserializer.scala
  28. +38 −47 src/main/scala/com/codahale/jerkson/deser/ScalaDeserializers.scala
  29. +16 −10 src/main/scala/com/codahale/jerkson/deser/SeqDeserializer.scala
  30. +4 −4 src/main/scala/com/codahale/jerkson/deser/StringBuilderDeserializer.scala
  31. +3 −5 src/main/scala/com/codahale/jerkson/ser/CaseClassSerializer.scala
  32. +2 −4 src/main/scala/com/codahale/jerkson/ser/EitherSerializer.scala
  33. +2 −4 src/main/scala/com/codahale/jerkson/ser/IterableSerializer.scala
  34. +2 −4 src/main/scala/com/codahale/jerkson/ser/IteratorSerializer.scala
  35. +2 −4 src/main/scala/com/codahale/jerkson/ser/JValueSerializer.scala
  36. +2 −4 src/main/scala/com/codahale/jerkson/ser/MapSerializer.scala
  37. +2 −4 src/main/scala/com/codahale/jerkson/ser/OptionSerializer.scala
  38. +2 −4 src/main/scala/com/codahale/jerkson/ser/RangeSerializer.scala
  39. +3 −3 src/main/scala/com/codahale/jerkson/ser/ScalaSerializers.scala
  40. +2 −4 src/main/scala/com/codahale/jerkson/ser/StringBuilderSerializer.scala
  41. +2 −2 src/main/scala/com/codahale/jerkson/util/CaseClassSigParser.scala
  42. +2 −2 src/test/scala/com/codahale/jerkson/tests/BasicTypeSupportSpec.scala
  43. +1 −1 src/test/scala/com/codahale/jerkson/tests/CaseClassSupportSpec.scala
  44. +1 −1 src/test/scala/com/codahale/jerkson/tests/EdgeCaseSpec.scala
  45. +2 −2 src/test/scala/com/codahale/jerkson/tests/ExampleCaseClasses.scala
View
@@ -1,4 +1,4 @@
-.idea
-.iml
+.idea*
+*.iml
target
View
10 pom.xml
@@ -15,7 +15,7 @@
<properties>
<scala.version>2.9.1</scala.version>
- <jackson.version>1.9.7</jackson.version>
+ <jackson.version>2.0.1</jackson.version>
</properties>
<developers>
@@ -59,13 +59,13 @@
<version>${scala.version}</version>
</dependency>
<dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-core-asl</artifactId>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-mapper-asl</artifactId>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
@@ -1,6 +1,6 @@
package com.codahale.jerkson;
-import org.codehaus.jackson.annotate.JacksonAnnotation;
+import com.fasterxml.jackson.annotation.JacksonAnnotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -1,7 +1,7 @@
package com.codahale.jerkson
-import org.codehaus.jackson.JsonFactory
-import org.codehaus.jackson.map.ObjectMapper
+import com.fasterxml.jackson.core.JsonFactory
+import com.fasterxml.jackson.databind.ObjectMapper
trait Factory {
/**
@@ -1,7 +1,7 @@
package com.codahale.jerkson
import java.io.{File, OutputStream, Writer, StringWriter}
-import org.codehaus.jackson.{JsonGenerator, JsonEncoding}
+import com.fasterxml.jackson.core.{JsonGenerator, JsonEncoding}
trait Generator extends Factory {
/**
@@ -1,7 +1,7 @@
package com.codahale.jerkson
-import org.codehaus.jackson.map.{MappingJsonFactory, ObjectMapper}
-import org.codehaus.jackson.{JsonGenerator, JsonParser => JacksonParser}
+import com.fasterxml.jackson.databind.{MappingJsonFactory, ObjectMapper}
+import com.fasterxml.jackson.core.{JsonGenerator, JsonParser => JacksonParser}
object Json extends Json
@@ -3,8 +3,9 @@ package com.codahale.jerkson
import io.Source
import java.net.URL
import com.codahale.jerkson.AST.{JValue, JNull}
-import org.codehaus.jackson.{JsonNode, JsonParser, JsonProcessingException}
-import org.codehaus.jackson.node.TreeTraversingParser
+import com.fasterxml.jackson.core.{JsonParser, JsonProcessingException}
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.node.TreeTraversingParser
import java.io.{EOFException, Reader, File, InputStream}
trait Parser extends Factory {
@@ -1,8 +1,8 @@
package com.codahale.jerkson
import java.io.IOException
-import org.codehaus.jackson.map.JsonMappingException
-import org.codehaus.jackson.{JsonParseException, JsonProcessingException}
+import com.fasterxml.jackson.databind.JsonMappingException
+import com.fasterxml.jackson.core.{JsonParseException, JsonProcessingException}
object ParsingException {
def apply(cause: JsonProcessingException): ParsingException = {
@@ -1,17 +1,17 @@
package com.codahale.jerkson
import deser.ScalaDeserializers
-import org.codehaus.jackson.map.Module.SetupContext
-import org.codehaus.jackson.Version
-import org.codehaus.jackson.map.Module
+import com.fasterxml.jackson.databind.Module.SetupContext
+import com.fasterxml.jackson.core.Version
+import com.fasterxml.jackson.databind.Module
import ser.ScalaSerializers
class ScalaModule(classLoader: ClassLoader) extends Module {
- def version = new Version(0, 2, 0, "")
+ def version = new Version(0, 6, 0, "SNAPSHOT", "com.codahale", "jerkson")
def getModuleName = "jerkson"
def setupModule(context: SetupContext) {
- context.addDeserializers(new ScalaDeserializers(classLoader))
+ context.addDeserializers(new ScalaDeserializers(classLoader, context))
context.addSerializers(new ScalaSerializers)
}
}
@@ -1,6 +1,6 @@
package com.codahale.jerkson
-import org.codehaus.jackson.{JsonToken, JsonParser}
+import com.fasterxml.jackson.core.{JsonToken, JsonParser}
class StreamingIterator[A](parser: JsonParser, mf: Manifest[A])
extends Iterator[A] {
@@ -1,7 +1,7 @@
package com.codahale.jerkson
-import org.codehaus.jackson.`type`.JavaType
-import org.codehaus.jackson.map.`type`.{TypeFactory, ArrayType}
+import com.fasterxml.jackson.databind.JavaType
+import com.fasterxml.jackson.databind.`type`.{TypeFactory, ArrayType}
import scala.collection.JavaConversions.asScalaConcurrentMap
import java.util.concurrent.ConcurrentHashMap
@@ -1,10 +1,8 @@
package com.codahale.jerkson.deser
-import org.codehaus.jackson.map.annotate.JsonCachable
-import org.codehaus.jackson.map.{DeserializationContext, JsonDeserializer}
-import org.codehaus.jackson.JsonParser
+import com.fasterxml.jackson.databind.{DeserializationContext, JsonDeserializer}
+import com.fasterxml.jackson.core.JsonParser
-@JsonCachable
class BigDecimalDeserializer extends JsonDeserializer[Object] {
def deserialize(jp: JsonParser, ctxt: DeserializationContext) = {
if (jp.getCurrentToken == null) {
@@ -18,4 +16,6 @@ class BigDecimalDeserializer extends JsonDeserializer[Object] {
throw ctxt.mappingException(classOf[BigDecimal])
}
}
+
+ override def isCachable = true
}
@@ -1,10 +1,8 @@
package com.codahale.jerkson.deser
-import org.codehaus.jackson.map.annotate.JsonCachable
-import org.codehaus.jackson.map.{DeserializationContext, JsonDeserializer}
-import org.codehaus.jackson.JsonParser
+import com.fasterxml.jackson.databind.{DeserializationContext, JsonDeserializer}
+import com.fasterxml.jackson.core.JsonParser
-@JsonCachable
class BigIntDeserializer extends JsonDeserializer[Object] {
def deserialize(jp: JsonParser, ctxt: DeserializationContext) = {
if (jp.getCurrentToken == null) {
@@ -18,4 +16,6 @@ class BigIntDeserializer extends JsonDeserializer[Object] {
throw ctxt.mappingException(classOf[BigInt])
}
}
+
+ override def isCachable = true
}
@@ -2,11 +2,9 @@ package com.codahale.jerkson.deser
import scala.collection.generic.BitSetFactory
import scala.collection.{BitSetLike, BitSet}
-import org.codehaus.jackson.map.{DeserializationContext, JsonDeserializer}
-import org.codehaus.jackson.{JsonToken, JsonParser}
-import org.codehaus.jackson.map.annotate.JsonCachable
+import com.fasterxml.jackson.databind.{DeserializationContext, JsonDeserializer}
+import com.fasterxml.jackson.core.{JsonToken, JsonParser}
-@JsonCachable
class BitSetDeserializer[Coll <: BitSet with BitSetLike[Coll]](factory: BitSetFactory[Coll])
extends JsonDeserializer[Coll] {
@@ -23,4 +21,6 @@ class BitSetDeserializer[Coll <: BitSet with BitSetLike[Coll]](factory: BitSetFa
builder.result()
}
+
+ override def isCachable = true
}
@@ -5,16 +5,13 @@ import scala.collection.mutable.ArrayBuffer
import com.codahale.jerkson.JsonSnakeCase
import com.codahale.jerkson.util._
import com.codahale.jerkson.Util._
-import org.codehaus.jackson.{JsonNode, JsonToken, JsonParser}
-import org.codehaus.jackson.map._
-import org.codehaus.jackson.map.annotate.JsonCachable
-import org.codehaus.jackson.node.{ObjectNode, NullNode, TreeTraversingParser}
-import org.codehaus.jackson.`type`.JavaType
+import com.fasterxml.jackson.databind._
+import com.fasterxml.jackson.databind.node.{ObjectNode, NullNode, TreeTraversingParser}
+import com.fasterxml.jackson.databind.JavaType
+import com.fasterxml.jackson.core.{JsonToken, JsonParser}
-@JsonCachable
class CaseClassDeserializer(config: DeserializationConfig,
javaType: JavaType,
- provider: DeserializerProvider,
classLoader: ClassLoader) extends JsonDeserializer[Object] {
private val isSnakeCase = javaType.getRawClass.isAnnotationPresent(classOf[JsonSnakeCase])
private val params = CaseClassSigParser.parse(javaType.getRawClass, config.getTypeFactory, classLoader).map {
@@ -48,7 +45,7 @@ class CaseClassDeserializer(config: DeserializationConfig,
throw ctxt.mappingException(javaType.getRawClass)
}
- val node = jp.readValueAsTree
+ val node = jp.readValueAsTree[JsonNode]
val values = new ArrayBuffer[AnyRef]
for ((paramName, paramType) <- params) {
@@ -77,10 +74,12 @@ class CaseClassDeserializer(config: DeserializationConfig,
private def errorMessage(node: JsonNode) = {
val names = params.map { _._1 }.mkString("[", ", ", "]")
val existing = node match {
- case obj: ObjectNode => obj.getFieldNames.mkString("[", ", ", "]")
+ case obj: ObjectNode => obj.fieldNames.mkString("[", ", ", "]")
case _: NullNode => "[]" // this is what Jackson deserializes the inside of an empty object to
case unknown => "a non-object"
}
"Invalid JSON. Needed %s, but found %s.".format(names, existing)
}
+
+ override def isCachable = true
}
@@ -1,17 +1,13 @@
package com.codahale.jerkson.deser
-import org.codehaus.jackson.JsonParser
-import org.codehaus.jackson.`type`.JavaType
-import org.codehaus.jackson.map.{DeserializerProvider, DeserializationConfig, DeserializationContext, JsonDeserializer}
-import org.codehaus.jackson.map.annotate.JsonCachable
-import org.codehaus.jackson.node.TreeTraversingParser
+import com.fasterxml.jackson.core.JsonParser
+import com.fasterxml.jackson.databind.node.TreeTraversingParser
+import com.fasterxml.jackson.databind._
-@JsonCachable
class EitherDeserializer(config: DeserializationConfig,
- javaType: JavaType,
- provider: DeserializerProvider) extends JsonDeserializer[Object] {
+ javaType: JavaType) extends JsonDeserializer[Object] {
def deserialize(jp: JsonParser, ctxt: DeserializationContext) = {
- val node = jp.readValueAsTree
+ val node = jp.readValueAsTree[JsonNode]
val tp = new TreeTraversingParser(node, jp.getCodec)
try {
@@ -20,4 +16,6 @@ class EitherDeserializer(config: DeserializationConfig,
case _ => Right(tp.getCodec.readValue[Object](tp, javaType.containedType(1)))
}
}
+
+ override def isCachable = true
}
@@ -1,19 +1,19 @@
package com.codahale.jerkson.deser
-import org.codehaus.jackson.`type`.JavaType
-import org.codehaus.jackson.map.{DeserializationContext, JsonDeserializer}
-import org.codehaus.jackson.{JsonToken, JsonParser}
-import org.codehaus.jackson.map.annotate.JsonCachable
+import com.fasterxml.jackson.databind.JavaType
+import com.fasterxml.jackson.databind.{DeserializationContext, JsonDeserializer}
+import com.fasterxml.jackson.core.{JsonToken, JsonParser}
import collection.generic.MapFactory
import collection.MapLike
+import com.fasterxml.jackson.databind.deser.ResolvableDeserializer
-@JsonCachable
class ImmutableMapDeserializer[CC[A, B] <: Map[A, B] with MapLike[A, B, CC[A, B]]](companion: MapFactory[CC],
- valueType: JavaType,
- valueDeserializer: JsonDeserializer[Object])
- extends JsonDeserializer[Object] {
+ valueType: JavaType)
+ extends JsonDeserializer[Object] with ResolvableDeserializer {
- def deserialize(jp: JsonParser, ctxt: DeserializationContext) = {
+ var valueDeserializer: JsonDeserializer[Object] = _
+
+ def deserialize(jp: JsonParser, ctxt: DeserializationContext): CC[String, Object] = {
val builder = companion.newBuilder[String, Object]
if (jp.getCurrentToken == JsonToken.START_OBJECT) {
@@ -34,4 +34,10 @@ class ImmutableMapDeserializer[CC[A, B] <: Map[A, B] with MapLike[A, B, CC[A, B]
builder.result()
}
+
+ def resolve(ctxt: DeserializationContext) {
+ valueDeserializer = ctxt.findRootValueDeserializer(valueType)
+ }
+
+ override def isCachable = true
}
@@ -1,14 +1,14 @@
package com.codahale.jerkson.deser
-import org.codehaus.jackson.map.annotate.JsonCachable
-import org.codehaus.jackson.map.{DeserializationContext, JsonDeserializer}
-import org.codehaus.jackson.{JsonToken, JsonParser}
-import org.codehaus.jackson.`type`.JavaType
+import com.fasterxml.jackson.databind.{DeserializationContext, JsonDeserializer}
+import com.fasterxml.jackson.core.{JsonToken, JsonParser}
+import com.fasterxml.jackson.databind.JavaType
import scala.collection.immutable.IntMap
+import com.fasterxml.jackson.databind.deser.ResolvableDeserializer
+
+class IntMapDeserializer(valueType: JavaType) extends JsonDeserializer[Object] with ResolvableDeserializer {
+ var valueDeserializer: JsonDeserializer[Object] = _
-@JsonCachable
-class IntMapDeserializer(valueType: JavaType,
- valueDeserializer: JsonDeserializer[Object]) extends JsonDeserializer[Object] {
def deserialize(jp: JsonParser, ctxt: DeserializationContext) = {
var map = IntMap.empty[Object]
@@ -34,4 +34,10 @@ class IntMapDeserializer(valueType: JavaType,
map
}
+
+ def resolve(ctxt: DeserializationContext) {
+ valueDeserializer = ctxt.findRootValueDeserializer(valueType)
+ }
+
+ override def isCachable = true
}
@@ -1,13 +1,13 @@
package com.codahale.jerkson.deser
-import org.codehaus.jackson.`type`.JavaType
-import org.codehaus.jackson.map.{DeserializationContext, JsonDeserializer}
-import org.codehaus.jackson.{JsonToken, JsonParser}
-import org.codehaus.jackson.map.annotate.JsonCachable
-
-@JsonCachable
-class IteratorDeserializer(elementType: JavaType,
- elementDeserializer: JsonDeserializer[Object]) extends JsonDeserializer[Object] {
+import com.fasterxml.jackson.databind.JavaType
+import com.fasterxml.jackson.databind.{DeserializationContext, JsonDeserializer}
+import com.fasterxml.jackson.core.{JsonToken, JsonParser}
+import com.fasterxml.jackson.databind.deser.ResolvableDeserializer
+
+class IteratorDeserializer(elementType: JavaType) extends JsonDeserializer[Object] with ResolvableDeserializer {
+ var elementDeserializer: JsonDeserializer[Object] = _
+
def deserialize(jp: JsonParser, ctxt: DeserializationContext) = {
val builder = Seq.newBuilder[Object]
@@ -16,9 +16,15 @@ class IteratorDeserializer(elementType: JavaType,
}
while (jp.nextToken() != JsonToken.END_ARRAY) {
- builder += elementDeserializer.deserialize(jp, ctxt).asInstanceOf[Object]
+ builder += elementDeserializer.deserialize(jp, ctxt)
}
builder.result().iterator.buffered
}
+
+ def resolve(ctxt: DeserializationContext) {
+ elementDeserializer = ctxt.findRootValueDeserializer(elementType)
+ }
+
+ override def isCachable = true
}
Oops, something went wrong.

0 comments on commit 9b874e5

Please sign in to comment.