Permalink
Browse files

Merge branch 'release/0.5.0'

  • Loading branch information...
2 parents 7f6bb37 + fe1bc9b commit e6ce1cd28a72ff8154feb21623ff9ddf15951096 @codahale committed Oct 8, 2011
View
@@ -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
@@ -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
@@ -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>
@@ -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
@@ -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>
@@ -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()
@@ -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 {
@@ -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,
@@ -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 =>
@@ -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
@@ -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) = {
@@ -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("$")
}
@@ -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
Oops, something went wrong.

0 comments on commit e6ce1cd

Please sign in to comment.