Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.lib/
.idea
.iml
lib_managed
Expand Down
121 changes: 35 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,99 +1,48 @@
Jerkson
-------
# Jerkson + Scala 2.10 + Streaming Iteration #

*Because I think you should use JSON.*
[Jerkson](https://github.com/codahale/jerkson) has only been published for
Scala versions as high as 2.9.1 and does not support streaming iteration.

Jerkson is a Scala wrapper for [Jackson](http://jackson.codehaus.org/) which
brings Scala's ease-of-use to Jackson's features.
## Differences from upstream Jerkson ##

- Streaming iteration is supported.
- sbt instead of Maven.
- Tests have been deleted, since sbt cannot run
[simplespec](https://github.com/SimpleFinance/simplespec) tests.
- Minor tweaks to get compilation in 2.10.

Requirements
------------
## Install ##

* Scala 2.8.2 or 2.9.1
* Jackson 1.9.x
- This version of Jerkson is hosted on
[Maven Central](http://central.maven.org/maven2/com/cloudphysics/).
- From sbt:

```scala
libraryDependencies += "com.cloudphysics" % "jerkson_2.10" % "0.5.1"
```
- From Maven:

Setting Up Your Project
-----------------------

Go ahead and add Jerkson as a dependency:

```xml
<repositories>
<repository>
<id>repo.codahale.com</id>
<url>http://repo.codahale.com</url>
</repository>
</repositories>

<dependencies>
```xml
<dependency>
<groupId>com.codahale</groupId>
<artifactId>jerkson_${scala.version}</artifactId>
<version>0.5.0</version>
<groupId>com.cloudphysics</groupId>
<artifactId>jerkson_2.10</artifactId>
<version>0.5.1</version>
</dependency>
</dependencies>
```


Parsing JSON
------------

```scala
import com.codahale.jerkson.Json._

// Parse JSON arrays
parse[List[Int]]("[1,2,3]") //=> List(1,2,3)

// Parse JSON objects
parse[Map[String, Int]]("""{"one":1,"two":2}""") //=> Map("one"->1,"two"->2)

// Parse JSON objects as case classes
// (Parsing case classes isn't supported in the REPL.)
case class Person(id: Long, name: String)
parse[Person]("""{"id":1,"name":"Coda"}""") //=> Person(1,"Coda")

// Parse streaming arrays of things
for (person <- stream[Person](inputStream)) {
println("New person: " + person)
}
```

For more examples, check out the [specs](https://github.com/codahale/jerkson/blob/master/src/test/scala/com/codahale/jerkson/tests/).


Generating JSON
---------------

```scala
// Generate JSON arrays
generate(List(1, 2, 3)) //=> [1,2,3]

// Generate JSON objects
generate(Map("one"->1, "two"->"dos")) //=> {"one":1,"two":"dos"}
```

For more examples, check out the [specs](https://github.com/codahale/jerkson/blob/master/src/test/scala/com/codahale/jerkson/tests/).


Handling `snake_case` Field Names
=================================

```scala
case class Person(firstName: String, lastName: String)

@JsonSnakeCase
case class Snake(firstName: String, lastName: String)

generate(Person("Coda", "Hale")) //=> {"firstName": "Coda","lastName":"Hale"}
generate(Snake("Windey", "Mover")) //=> {"first_name": "Windey","last_name":"Mover"}
```
```

## Build ##

License
-------
- Just compile:
```sh
$ cd jerkson
$ ./sbt compile
```
- Publish:
```sh
$ ./sbt publish
```

Copyright (c) 2010-2011 Coda Hale
## Contact ##

Published under The MIT License, see LICENSE
Repo maintained by [Yuvi Masory](http://yuvimasory.com).
[ymasory@gmail.com](ymasory@gmail.com)
111 changes: 111 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/* basic project info */
name := "jerkson"

organization := "com.cloudphysics"

version := "0.5.1-SNAPSHOT"

licenses := Seq(
("The MIT License", url("http://codahale.com/mit.txt"))
)

scmInfo := Some(
ScmInfo(
url("https://github.com/cphylabs/jerkson"),
"scm:git:https://github.com/cphylabs/jerkson.git",
Some("scm:git:git@github.com:cphylabs/jerkson.git")
)
)

/* scala versions and options */
scalaVersion := "2.10.1"

// These options will be used for *all* versions.
scalacOptions ++= Seq(
// "-deprecation",
"-unchecked",
"-encoding", "UTF-8",
"-optimise"
)

scalacOptions ++= Seq(
"-Yclosure-elim",
"-Yinline"
)

// javaOptions ++= Seq(
// "-Dscalac.patmat.analysisBudget=512"
// )


// These language flags will be used only for 2.10.x.
// Uncomment those you need, or if you hate SIP-18, all of them.
scalacOptions <++= scalaVersion map { sv =>
if (sv startsWith "2.10") List(
"-Xverify",
"-Ywarn-all",
"-feature",
"-language:postfixOps",
"-language:reflectiveCalls",
"-language:implicitConversions",
"-language:higherKinds",
"-language:existentials"
)
else Nil
}

javacOptions ++= Seq("-Xlint:unchecked", "-Xlint:deprecation")

/* dependencies */
libraryDependencies ++= Seq(
"org.codehaus.jackson" % "jackson-core-asl" % "1.9.12",
"org.codehaus.jackson" % "jackson-mapper-asl" % "1.9.12"
)

libraryDependencies <+= scalaVersion {
"org.scala-lang" % "scala-reflect" % _
}

resolvers ++= Seq(
"Local Maven" at Path.userHome.asFile.toURI.toURL + ".m2/repository"
)


/* testing */
parallelExecution in Test := false

/* sbt behavior */
logLevel in compile := Level.Warn

traceLevel := 5

offline := false

/* publishing */
publishMavenStyle := true

publishTo <<= version { (v: String) =>
val nexus = "https://oss.sonatype.org/"
if (v.trim.endsWith("SNAPSHOT")) Some(
"snapshots" at nexus + "content/repositories/snapshots"
)
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
}

publishArtifact in Test := false

pomIncludeRepository := { _ => false }

pomExtra := (
<developers>
<developer>
<id>ymasory</id>
<name>Yuvi Masory</name>
<email>yuvi@cloudphysics.com</email>
</developer>
</developers>
)

// Josh Suereth's step-by-step guide to publishing on sonatype
// http://www.scala-sbt.org/using_sonatype.html

Loading