Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'release/0.5.0'

  • Loading branch information...
commit e6ce1cd28a72ff8154feb21623ff9ddf15951096 2 parents 7f6bb37 + fe1bc9b
@codahale authored
View
8 CHANGELOG.md
@@ -1,3 +1,11 @@
+v0.5.0: Oct 07 2011
+===================
+
+* Added `canSerialize` and `canDeserialize`.
+* Upgraded Jackson to 1.9.0.
+* Dropped support for Scala 2.8.1, added support for 2.8.2. Upgrade.
+* Dropped support for 2.9.0-1. Upgrade.
+
v0.4.2: Sep 16 2011
===================
View
6 README.md
@@ -10,8 +10,8 @@ brings Scala's ease-of-use to Jackson's features.
Requirements
------------
-* Scala 2.8.1 or 2.9.0-1 or 2.9.1
-* Jackson 1.8.x
+* Scala 2.8.2 or 2.9.1
+* Jackson 1.9.x
Setting Up Your Project
@@ -31,7 +31,7 @@ Go ahead and add Jerkson as a dependency:
<dependency>
<groupId>com.codahale</groupId>
<artifactId>jerkson_${scala.version}</artifactId>
- <version>0.4.2</version>
+ <version>0.5.0</version>
</dependency>
</dependencies>
```
View
15 pom.xml
@@ -6,12 +6,12 @@
<groupId>com.codahale</groupId>
<artifactId>jerkson_2.9.1</artifactId>
- <version>0.4.2</version>
+ <version>0.5.0</version>
<name>Jerkson for Scala ${scala.version}</name>
<properties>
<scala.version>2.9.1</scala.version>
- <jackson.version>[1.8.0,1.9.0)</jackson.version>
+ <jackson.version>[1.9.0,2.0.0)</jackson.version>
</properties>
<developers>
@@ -39,6 +39,10 @@
<id>repo.codahale.com</id>
<url>http://repo.codahale.com</url>
</repository>
+ <repository>
+ <id>nativelibs4java</id>
+ <url>http://nativelibs4java.sourceforge.net/maven</url>
+ </repository>
</repositories>
<pluginRepositories>
@@ -123,6 +127,13 @@
<arg>-unchecked</arg>
<arg>-deprecation</arg>
</args>
+ <compilerPlugins>
+ <compilerPlugin>
+ <groupId>com.nativelibs4java</groupId>
+ <artifactId>scalacl-compiler-plugin</artifactId>
+ <version>0.2</version>
+ </compilerPlugin>
+ </compilerPlugins>
<charset>UTF-8</charset>
</configuration>
</plugin>
View
10 pom_2.8.1.xml → pom_2.8.2.xml
@@ -5,13 +5,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.codahale</groupId>
- <artifactId>jerkson_2.8.1</artifactId>
- <version>0.4.2</version>
+ <artifactId>jerkson_2.8.2</artifactId>
+ <version>0.5.0</version>
<name>Jerkson for Scala ${scala.version}</name>
<properties>
- <scala.version>2.8.1</scala.version>
- <jackson.version>[1.8.0,1.9.0)</jackson.version>
+ <scala.version>2.8.2</scala.version>
+ <jackson.version>[1.9.0,2.0.0)</jackson.version>
</properties>
<developers>
@@ -73,7 +73,7 @@
</dependency>
<dependency>
<groupId>com.codahale</groupId>
- <artifactId>simplespec_${scala.version}</artifactId>
+ <artifactId>simplespec_2.8.1</artifactId>
<version>[0.5.0,0.6.0)</version>
<scope>test</scope>
</dependency>
View
184 pom_2.9.0-1.xml
@@ -1,184 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <groupId>com.codahale</groupId>
- <artifactId>jerkson_2.9.0-1</artifactId>
- <version>0.4.2</version>
- <name>Jerkson for Scala ${scala.version}</name>
-
- <properties>
- <scala.version>2.9.0-1</scala.version>
- <jackson.version>[1.8.0,1.9.0)</jackson.version>
- </properties>
-
- <developers>
- <developer>
- <name>Coda Hale</name>
- <email>coda.hale@gmail.com</email>
- <timezone>-8</timezone>
- </developer>
- </developers>
-
- <licenses>
- <license>
- <url>http://codahale.com/mit.txt</url>
- <name>The MIT License</name>
- <distribution>repo</distribution>
- </license>
- </licenses>
-
- <repositories>
- <repository>
- <id>scala-tools-releases</id>
- <url>http://scala-tools.org/repo-releases/</url>
- </repository>
- <repository>
- <id>repo.codahale.com</id>
- <url>http://repo.codahale.com</url>
- </repository>
- </repositories>
-
- <pluginRepositories>
- <pluginRepository>
- <id>scala-tools-releases</id>
- <url>http://scala-tools.org/repo-releases/</url>
- </pluginRepository>
- </pluginRepositories>
-
- <distributionManagement>
- <repository>
- <id>repo.codahale.com</id>
- <url>scp://codahale.com/home/codahale/repo.codahale.com</url>
- </repository>
- </distributionManagement>
-
- <dependencies>
- <dependency>
- <groupId>org.scala-lang</groupId>
- <artifactId>scala-library</artifactId>
- <version>${scala.version}</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-core-asl</artifactId>
- <version>${jackson.version}</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-mapper-asl</artifactId>
- <version>${jackson.version}</version>
- </dependency>
- <dependency>
- <groupId>com.codahale</groupId>
- <artifactId>simplespec_${scala.version}</artifactId>
- <version>[0.5.0,0.6.0)</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <profiles>
- <profile>
- <id>sign</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-gpg-plugin</artifactId>
- <version>1.2</version>
- <executions>
- <execution>
- <id>sign-artifacts</id>
- <phase>verify</phase>
- <goals>
- <goal>sign</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.scala-tools</groupId>
- <artifactId>maven-scala-plugin</artifactId>
- <version>2.15.2</version>
- <executions>
- <execution>
- <goals>
- <goal>compile</goal>
- <goal>testCompile</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <args>
- <arg>-optimise</arg>
- <arg>-unchecked</arg>
- <arg>-deprecation</arg>
- </args>
- <charset>UTF-8</charset>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- <version>2.1.2</version>
- <executions>
- <execution>
- <id>attach-sources</id>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <version>2.5</version>
- <configuration>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.8.1</version>
- <configuration>
- <useSystemClassLoader>false</useSystemClassLoader>
- <argLine>-Xmx1024m</argLine>
- <includes>
- <include>**/*Spec.java</include>
- </includes>
- <excludes>
- <exclude>**/*Test.java</exclude>
- </excludes>
- </configuration>
- </plugin>
- </plugins>
- <extensions>
- <extension>
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-ssh</artifactId>
- <version>1.0-beta-7</version>
- </extension>
- </extensions>
- </build>
-</project>
View
5 src/main/scala/com/codahale/jerkson/Generator.scala
@@ -34,6 +34,11 @@ trait Generator extends Factory {
generate(obj, factory.createJsonGenerator(output, JsonEncoding.UTF8))
}
+ /**
+ * Returns true if the given class is serializable.
+ */
+ def canSerialize[A](implicit mf: Manifest[A]) = mapper.canSerialize(mf.erasure)
+
private def generate[A](obj: A, generator: JsonGenerator) {
generator.writeObject(obj)
generator.close()
View
10 src/main/scala/com/codahale/jerkson/Parser.scala
@@ -69,12 +69,14 @@ trait Parser extends Factory {
new StreamingIterator[A](parser, mf)
}
+ /**
+ * Returns true if the given class is deserializable.
+ */
+ def canDeserialize[A](implicit mf: Manifest[A]) = mapper.canDeserialize(Types.build(mapper.getTypeFactory, mf))
+
private[jerkson] def parse[A](parser: JsonParser, mf: Manifest[A]): A = {
try {
- if (mf.erasure == classOf[Option[_]]) {
- // thanks for special-casing VALUE_NULL, guys
- Option(parse(parser, mf.typeArguments.head)).asInstanceOf[A]
- } else if (mf.erasure == classOf[JValue] || mf.erasure == JNull.getClass) {
+ if (mf.erasure == classOf[JValue] || mf.erasure == JNull.getClass) {
val value: A = parser.getCodec.readValue(parser, Types.build(mapper.getTypeFactory, mf))
if (value == null) JNull.asInstanceOf[A] else value
} else {
View
2  src/main/scala/com/codahale/jerkson/Types.scala
@@ -13,7 +13,7 @@ private[jerkson] object Types {
private def constructType(factory: TypeFactory, manifest: Manifest[_]): JavaType = {
if (manifest.erasure.isArray) {
- ArrayType.construct(factory.constructType(manifest.erasure.getComponentType))
+ ArrayType.construct(factory.constructType(manifest.erasure.getComponentType), null, null)
} else {
factory.constructParametricType(
manifest.erasure,
View
6 src/main/scala/com/codahale/jerkson/deser/CaseClassDeserializer.scala
@@ -17,9 +17,9 @@ class CaseClassDeserializer(config: DeserializationConfig,
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 { case (name, jt) =>
- (if (isSnakeCase) snakeCase(name) else name, jt)
- }
+ private val params = CaseClassSigParser.parse(javaType.getRawClass, config.getTypeFactory, classLoader).map {
+ case (name, jt) => (if (isSnakeCase) snakeCase(name) else name, jt)
+ }.toArray
private val paramTypes = params.map { _._2.getRawClass }.toList
private val constructor = javaType.getRawClass.getConstructors.find { c =>
val constructorTypes = c.getParameterTypes.toList.map { t =>
View
4 src/main/scala/com/codahale/jerkson/deser/OptionDeserializer.scala
@@ -10,6 +10,10 @@ class OptionDeserializer(elementType: JavaType,
elementDeserializer: JsonDeserializer[Object])
extends JsonDeserializer[Object] {
+ override def getEmptyValue = None
+
+ override def getNullValue = None
+
def deserialize(jp: JsonParser, ctxt: DeserializationContext) = {
if (jp.getCurrentToken == JsonToken.VALUE_NULL) {
None
View
2  src/main/scala/com/codahale/jerkson/deser/ScalaDeserializers.scala
@@ -6,7 +6,7 @@ import scala.collection.{Traversable, MapLike, immutable, mutable}
import com.codahale.jerkson.AST.{JNull, JValue}
import scala.collection.generic.{MapFactory, GenericCompanion}
-class ScalaDeserializers(classLoader: ClassLoader) extends Deserializers.None {
+class ScalaDeserializers(classLoader: ClassLoader) extends Deserializers.Base {
override def findBeanDeserializer(javaType: JavaType, config: DeserializationConfig,
provider: DeserializerProvider, beanDesc: BeanDescription,
property: BeanProperty) = {
View
2  src/main/scala/com/codahale/jerkson/ser/CaseClassSerializer.scala
@@ -17,7 +17,7 @@ class CaseClassSerializer[A <: Product](klass: Class[_]) extends JsonSerializer[
private val nonIgnoredFields = klass.getDeclaredFields.filterNot { f =>
f.getAnnotation(classOf[JsonIgnore]) != null ||
- ignoredFields.contains(f.getName) ||
+ ignoredFields(f.getName) ||
(f.getModifiers & Modifier.TRANSIENT) != 0 ||
f.getName.contains("$")
}
View
2  src/main/scala/com/codahale/jerkson/ser/ScalaSerializers.scala
@@ -4,7 +4,7 @@ import org.codehaus.jackson.`type`.JavaType
import com.codahale.jerkson.AST.JValue
import org.codehaus.jackson.map._
-class ScalaSerializers extends Serializers.None {
+class ScalaSerializers extends Serializers.Base {
override def findSerializer(config: SerializationConfig, javaType: JavaType, beanDesc: BeanDescription, beanProp: BeanProperty) = {
val ser: Object = if (classOf[Option[_]].isAssignableFrom(beanDesc.getBeanClass)) {
new OptionSerializer
View
30 src/main/scala/com/codahale/jerkson/util/CaseClassSigParser.scala
@@ -91,12 +91,30 @@ object CaseClassSigParser {
protected def typeRef2JavaType(ref: TypeRefType, factory: TypeFactory, classLoader: ClassLoader): JavaType = {
try {
- val klass = loadClass(ref.symbol.path, classLoader)
- factory.constructParametricType(
- klass, ref.typeArgs.map {
- t => typeRef2JavaType(t.asInstanceOf[TypeRefType], factory, classLoader)
- }: _*
- )
+ if (ref.symbol.path == "scala.Array") {
+ val elementType = typeRef2JavaType(ref.typeArgs.head.asInstanceOf[TypeRefType], factory, classLoader)
+ val realElementType = elementType.getRawClass.getName match {
+ case "java.lang.Boolean" => classOf[Boolean]
+ case "java.lang.Byte" => classOf[Byte]
+ case "java.lang.Character" => classOf[Char]
+ case "java.lang.Double" => classOf[Double]
+ case "java.lang.Float" => classOf[Float]
+ case "java.lang.Integer" => classOf[Int]
+ case "java.lang.Long" => classOf[Long]
+ case "java.lang.Short" => classOf[Short]
+ case _ => elementType.getRawClass
+ }
+
+ val array = java.lang.reflect.Array.newInstance(realElementType, 0)
+ factory.constructType(array.getClass)
+ } else {
+ val klass = loadClass(ref.symbol.path, classLoader)
+ factory.constructParametricType(
+ klass, ref.typeArgs.map {
+ t => typeRef2JavaType(t.asInstanceOf[TypeRefType], factory, classLoader)
+ }: _*
+ )
+ }
} catch {
case e: Throwable => {
e.printStackTrace()
View
16 src/test/scala/com/codahale/jerkson/tests/CaseClassSupportSpec.scala
@@ -220,4 +220,20 @@ class CaseClassSupportSpec extends Spec {
}.must(throwA[ParsingException]("Invalid JSON. Needed [one_thing, two_thing], but found [one_thing]."))
}
}
+
+ class `A case class with array members` {
+ @Test def `is parsable from a JSON object` = {
+ val c = parse[CaseClassWithArrays]("""{"one":"1","two":["a","b","c"],"three":[1,2,3]}""")
+
+ c.one.must(be("1"))
+ c.two.must(be(Array("a", "b", "c")))
+ c.three.must(be(Array(1, 2, 3)))
+ }
+
+ @Test def `generates a JSON object` = {
+ generate(CaseClassWithArrays("1", Array("a", "b", "c"), Array(1, 2, 3))).must(be(
+ """{"one":"1","two":["a","b","c"],"three":[1,2,3]}"""
+ ))
+ }
+ }
}
View
2  src/test/scala/com/codahale/jerkson/tests/ExampleCaseClasses.scala
@@ -70,3 +70,5 @@ case class CaseClassWithTwoConstructors(id: Long, name: String) {
@JsonSnakeCase
case class CaseClassWithSnakeCase(oneThing: String, twoThing: String)
+
+case class CaseClassWithArrays(one: String, two: Array[String], three: Array[Int])
Please sign in to comment.
Something went wrong with that request. Please try again.