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

Add a JSON parsing API that returns Try or similar type instead of throwing exception #700

Open
joelvim opened this issue Jan 19, 2022 · 1 comment · May be fixed by #987
Open

Add a JSON parsing API that returns Try or similar type instead of throwing exception #700

joelvim opened this issue Jan 19, 2022 · 1 comment · May be fixed by #987

Comments

@joelvim
Copy link

joelvim commented Jan 19, 2022

Currently, when JSON.parse processes invalid JSON, it will throw an exception. This is not documented and can be misleading for some users that will forget to catch the exceptions.

It would be ideal to have a new API (not to break compatibility) with a signature like

def tryParse(input: String): Try[JsValue] // or with Either or similar type that encodes error

def tryParse(input: InputStream): Try[JsValue]

def tryParse(input: Array[Byte]): Try[JsValue]

in order to use the type system to prevent user mistakes.

If it is not possible at all to add a new API, at least it would be important to document that exceptions can be thrown.

Play JSON Version

2.9.x

API

Scala

@cchantep
Copy link
Member

Will have a look

cchantep added a commit to cchantep/play-json that referenced this issue Feb 25, 2024
@cchantep cchantep linked a pull request Feb 25, 2024 that will close this issue
5 tasks
cchantep added a commit to cchantep/play-json that referenced this issue May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants