Created
October 29, 2011 06:27
-
-
Save itang/1324171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test | |
import com.codahale.jerkson.Json._ | |
import scala.reflect.BeanInfo | |
import scala.reflect.BeanProperty | |
object TestJerkson extends App { | |
def p(t: Any) = println(generate(t)) | |
implicit def pw(t: Any) = new { | |
def output_json = p(t) | |
} | |
List(1, 2, 3) output_json | |
// null | |
p(null) | |
//AnyVal | |
p(1) | |
p(1L) | |
p(true) | |
p("some") | |
//Array | |
p(Array(1, 2, 3, 4, 4)) | |
p(Array((1 to 10).toList)) | |
//Option | Some | None | |
(Option(null)).output_json | |
(Some("hello")).output_json | |
(None).output_json | |
//Map | |
(Map(1 -> "hello", 2 -> "world")).output_json | |
//Seq | |
p(Seq(1, 2, 3, 4)) | |
//List | |
p((1 to 10).toList) | |
//Ranage | |
p(1 to 10) | |
p(Set(1, 2, 2, 3, 4, 5)) | |
//Tuple | |
p(Tuple2("hello", "world")) | |
p("msg" -> "Hello,") | |
//case class | |
CaseClass("tqibm", 18).output_json | |
new Immutabler("livetang", 18).output_json | |
//Java Map | |
p(new java.util.HashMap[String, String] { put("name", "itang") }) | |
//Bean | |
var user = new User("itang", "test") | |
p(user) | |
} | |
case class CaseClass(name: String, age: Int) { | |
def getPassword() = "test" | |
} | |
class Immutabler(@BeanProperty val name: String, @BeanProperty val age: Int) { | |
def getPassword() = "Immutabler-test" | |
} | |
class User(var name: String, var password: String) { | |
def getName() = "T_" + name | |
def getPassword() = "T_" + password | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment