diff options
author | Johannes Rudolph <johannes.rudolph@gmail.com> | 2018-11-07 14:50:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-07 14:50:18 +0100 |
commit | ddb4e1e7c0e28f06f703dd5e325b59fd0548bd97 (patch) | |
tree | 9f48a32ca9ce0cf5bd17f993e4556ebdaa661866 /src/main/scala | |
parent | 414948434f70d3279215686251315818a49e66f9 (diff) | |
parent | 3ccb0768cb5ccb0c4b577742ee7f1ec7d3b9c83f (diff) | |
download | spray-json-ddb4e1e7c0e28f06f703dd5e325b59fd0548bd97.tar.gz spray-json-ddb4e1e7c0e28f06f703dd5e325b59fd0548bd97.tar.bz2 spray-json-ddb4e1e7c0e28f06f703dd5e325b59fd0548bd97.zip |
Merge pull request #282 from jrudolph/introduce-JsonParserSettings
Introduce JsonParserSettings to allow customization of parsing
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/spray/json/JsonParser.scala | 5 | ||||
-rw-r--r-- | src/main/scala/spray/json/JsonParserSettings.scala | 10 | ||||
-rw-r--r-- | src/main/scala/spray/json/package.scala | 3 |
3 files changed, 16 insertions, 2 deletions
diff --git a/src/main/scala/spray/json/JsonParser.scala b/src/main/scala/spray/json/JsonParser.scala index 71c4c11..f29c062 100644 --- a/src/main/scala/spray/json/JsonParser.scala +++ b/src/main/scala/spray/json/JsonParser.scala @@ -26,12 +26,15 @@ import java.nio.charset.Charset */ object JsonParser { def apply(input: ParserInput): JsValue = new JsonParser(input).parseJsValue() + def apply(input: ParserInput, settings: JsonParserSettings): JsValue = new JsonParser(input, settings).parseJsValue() class ParsingException(val summary: String, val detail: String = "") extends RuntimeException(if (summary.isEmpty) detail else if (detail.isEmpty) summary else summary + ":" + detail) } -class JsonParser(input: ParserInput) { +class JsonParser(input: ParserInput, settings: JsonParserSettings = JsonParserSettings.default) { + def this(input: ParserInput) = this(input, JsonParserSettings.default) + import JsonParser.ParsingException private[this] val sb = new JStringBuilder diff --git a/src/main/scala/spray/json/JsonParserSettings.scala b/src/main/scala/spray/json/JsonParserSettings.scala new file mode 100644 index 0000000..31692fd --- /dev/null +++ b/src/main/scala/spray/json/JsonParserSettings.scala @@ -0,0 +1,10 @@ +package spray.json + +trait JsonParserSettings { + +} +object JsonParserSettings { + val default: JsonParserSettings = SettingsImpl() + + private case class SettingsImpl() extends JsonParserSettings +}
\ No newline at end of file diff --git a/src/main/scala/spray/json/package.scala b/src/main/scala/spray/json/package.scala index 37d63c2..a8a42f0 100644 --- a/src/main/scala/spray/json/package.scala +++ b/src/main/scala/spray/json/package.scala @@ -24,7 +24,7 @@ package object json { def serializationError(msg: String) = throw new SerializationException(msg) def jsonReader[T](implicit reader: JsonReader[T]) = reader - def jsonWriter[T](implicit writer: JsonWriter[T]) = writer + def jsonWriter[T](implicit writer: JsonWriter[T]) = writer implicit def enrichAny[T](any: T) = new RichAny(any) implicit def enrichString(string: String) = new RichString(string) @@ -48,6 +48,7 @@ package json { @deprecated("deprecated in favor of parseJson", "1.2.6") def asJson: JsValue = parseJson def parseJson: JsValue = JsonParser(string) + def parseJson(settings: JsonParserSettings): JsValue = JsonParser(string, settings) } @deprecated("use RichAny", "1.3.4") |