Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Revert "Add support for parsing via Class[A]."
Browse files Browse the repository at this point in the history
This reverts commit d592703.

Reopens #22.

I hate you, Scala 2.8.1. I hate you, people who use it.
  • Loading branch information
codahale committed Sep 16, 2011
1 parent d592703 commit 5d47ca4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
10 changes: 0 additions & 10 deletions src/main/scala/com/codahale/jerkson/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,36 @@ trait Parser extends Factory {
* Parse a JSON string as a particular type.
*/
def parse[A](input: String)(implicit mf: Manifest[A]): A = parse[A](factory.createJsonParser(input), mf)
def parse[A](input: String, klass: Class[A]): A = parse[A](input)(Manifest.classType(klass))

/**
* Parse a JSON input stream as a particular type.
*/
def parse[A](input: InputStream)(implicit mf: Manifest[A]): A = parse[A](factory.createJsonParser(input), mf)
def parse[A](input: InputStream, klass: Class[A]): A = parse[A](input)(Manifest.classType(klass))

/**
* Parse a JSON file as a particular type.
*/
def parse[A](input: File)(implicit mf: Manifest[A]): A = parse[A](factory.createJsonParser(input), mf)
def parse[A](input: File, klass: Class[A]): A = parse[A](input)(Manifest.classType(klass))

/**
* Parse a JSON URL as a particular type.
*/
def parse[A](input: URL)(implicit mf: Manifest[A]): A = parse[A](factory.createJsonParser(input), mf)
def parse[A](input: URL, klass: Class[A]): A = parse[A](input)(Manifest.classType(klass))

/**
* Parse a JSON Reader as a particular type.
*/
def parse[A](input: Reader)(implicit mf: Manifest[A]): A = parse[A](factory.createJsonParser(input), mf)
def parse[A](input: Reader, klass: Class[A]): A = parse[A](input)(Manifest.classType(klass))

/**
* Parse a JSON byte array as a particular type.
*/
def parse[A](input: Array[Byte])(implicit mf: Manifest[A]): A = parse[A](factory.createJsonParser(input), mf)
def parse[A](input: Array[Byte], klass: Class[A]): A = parse[A](input)(Manifest.classType(klass))

/**
* Parse a JSON Source as a particular type.
*/
def parse[A](input: Source)(implicit mf: Manifest[A]): A = parse[A](input.mkString)
def parse[A](input: Source, klass: Class[A]): A = parse[A](input)(Manifest.classType(klass))

/**
* Parse a JSON node as a particular type.
Expand All @@ -57,7 +50,6 @@ trait Parser extends Factory {
val parser = new TreeTraversingParser(input, mapper)
parse(parser, mf)
}
def parse[A](input: JsonNode, klass: Class[A]): A = parse[A](input)(Manifest.classType(klass))

/**
* Parse a streaming JSON array of particular types, returning an iterator
Expand All @@ -67,7 +59,6 @@ trait Parser extends Factory {
val parser = factory.createJsonParser(input)
new StreamingIterator[A](parser, mf)
}
def stream[A](input: InputStream, klass: Class[A]): Iterator[A] = stream[A](input)(Manifest.classType(klass))

/**
* Parse a streaming JSON array of particular types, returning an iterator
Expand All @@ -77,7 +68,6 @@ trait Parser extends Factory {
val parser = factory.createJsonParser(input)
new StreamingIterator[A](parser, mf)
}
def stream[A](input: Reader, klass: Class[A]): Iterator[A] = stream[A](input)(Manifest.classType(klass))

private[jerkson] def parse[A](parser: JsonParser, mf: Manifest[A]): A = {
try {
Expand Down
12 changes: 3 additions & 9 deletions src/test/scala/com/codahale/jerkson/tests/EdgeCaseSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class EdgeCaseSpec extends Spec {
}

class `Parsing malformed JSON` {
@Test def `throws a ParsingException with an informative message` = {
@Test def `should throw a ParsingException with an informative message` = {
evaluating {
parse[Boolean]("jjf8;09")
}.must(throwA[ParsingException](
Expand All @@ -45,7 +45,7 @@ class EdgeCaseSpec extends Spec {
}

class `Parsing invalid JSON` {
@Test def `throws a ParsingException with an informative message` = {
@Test def `should throw a ParsingException with an informative message` = {
evaluating {
parse[CaseClass]("900")
}.must(throwA[ParsingException](
Expand All @@ -59,17 +59,11 @@ class EdgeCaseSpec extends Spec {
}

class `Parsing an empty document` {
@Test def `throws a ParsingException with an informative message` = {
@Test def `should throw a ParsingException with an informative message` = {
val input = new ByteArrayInputStream(Array.empty)
evaluating {
parse[CaseClass](input)
}.must(throwA[ParsingException]("JSON document ended unexpectedly."))
}
}

class `Parsing a document with a Class[A]` {
@Test def `works` = {
parse("\"womp\"", classOf[String]).must(be("womp"))
}
}
}

0 comments on commit 5d47ca4

Please sign in to comment.