fixed bug in Serializer API, added a sample test case for Serializer, added a new jar for sjson to embedded_repo

This commit is contained in:
Debasish Ghosh 2010-02-17 16:02:50 +05:30
parent 21f7df204e
commit c871e0184c
5 changed files with 48 additions and 9 deletions

View file

@ -152,7 +152,14 @@ object Serializer {
// FIXME set ClassLoader on SJSONSerializer.SJSON
def in(bytes: Array[Byte], clazz: Option[Class[_]]): AnyRef = SJSONSerializer.SJSON.in(bytes)
def in(json: String): AnyRef = SJSONSerializer.SJSON.in(json)
import scala.reflect.Manifest
def in[T](json: String)(implicit m: Manifest[T]): AnyRef = {
SJSONSerializer.SJSON.in(json)(m)
}
def in[T](bytes: Array[Byte])(implicit m: Manifest[T]): AnyRef = {
SJSONSerializer.SJSON.in(bytes)(m)
}
}
/**

View file

@ -0,0 +1,40 @@
package se.scalablesolutions.akka.serialization
import junit.framework.TestCase
import org.scalatest.junit.JUnitSuite
import org.junit.{Test, Before, After}
import scala.reflect.BeanInfo
@BeanInfo
case class Foo(foo: String) {
def this() = this(null)
}
@BeanInfo
case class MyMessage(val id: String, val value: Tuple2[String, Int]) {
private def this() = this(null, null)
}
class SerializerTest extends JUnitSuite {
@Test
def shouldSerializeString = {
val f = Foo("debasish")
val json = Serializer.ScalaJSON.out(f)
assert(new String(json) == """{"foo":"debasish"}""")
val fo = Serializer.ScalaJSON.in[Foo](new String(json)).asInstanceOf[Foo]
assert(fo == f)
}
@Test
def shouldSerializeTuple2 = {
val message = MyMessage("id", ("hello", 34))
val json = Serializer.ScalaJSON.out(message)
assert(new String(json) == """{"id":"id","value":{"hello":34}}""")
val f = Serializer.ScalaJSON.in[MyMessage](new String(json)).asInstanceOf[MyMessage]
assert(f == message)
val g = Serializer.ScalaJSON.in[MyMessage](json).asInstanceOf[MyMessage]
assert(f == message)
}
}

View file

@ -1,8 +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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sjson.json</groupId>
<artifactId>sjson</artifactId>
<version>0.3</version>
<packaging>jar</packaging>
</project>