Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot directly parse JSON string literal #1

Closed
zgrannan opened this issue Jan 5, 2022 · 2 comments
Closed

Cannot directly parse JSON string literal #1

zgrannan opened this issue Jan 5, 2022 · 2 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@zgrannan
Copy link

zgrannan commented Jan 5, 2022

It appears that attempt to parse a string literal (not enclosed in an object), leads to an error:

  "Json.parse" should "work" in {
    Json.parse("\"test\"")
  }

yields

[info] - should work *** FAILED ***
[info]   grapple.json.JsonParserError: Unexpected character '"' at offset 0
[info]   at grapple.json.JsonParserError$.apply(JsonException.scala:50)
[info]   at grapple.json.JsonParserImpl.unexpectedChar(JsonParserImpl.scala:300)
[info]   at grapple.json.JsonParserImpl.firstEvent(JsonParserImpl.scala:117)
[info]   at grapple.json.JsonParserImpl.init$$anonfun$1(JsonParserImpl.scala:97)
[info]   at scala.util.Try$.apply(Try.scala:210)
[info]   at grapple.json.JsonParserImpl.init(JsonParserImpl.scala:97)
[info]   at grapple.json.JsonParserImpl.hasNext(JsonParserImpl.scala:43)
[info]   at grapple.json.JsonParserImpl.next(JsonParserImpl.scala:49)
[info]   at grapple.json.JsonReaderImpl.read(JsonReaderImpl.scala:27)
[info]   at grapple.json.Json$.parse(Json.scala:59)
@losizm
Copy link
Owner

losizm commented Jan 5, 2022

Json.parse(String) is intended for JSON structures only – i.e., JsonObject and JsonArray. Although not expressly stated, see return type for Json in scaladoc.

That said, I will consider changing the implementation to parse any JSON value... and will most certainly update the documentation.

Much thanks for your input.

@losizm losizm added documentation Improvements or additions to documentation enhancement New feature or request labels Jan 5, 2022
losizm added a commit that referenced this issue Feb 5, 2023
See also Issue #1
@losizm
Copy link
Owner

losizm commented Feb 5, 2023

The scaladoc for all parse methods is updated. An annotation is applied indicating that JsonParserError is thrown if argument cannot be parsed to JSON structure. See commit 9fc4520.

No enhancement is applied to parse other JSON values.

@losizm losizm closed this as completed Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants