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

JsonSyntaxException is not thrown when provided an invalid JSON #941

Open
salih opened this issue Oct 7, 2024 · 6 comments
Open

JsonSyntaxException is not thrown when provided an invalid JSON #941

salih opened this issue Oct 7, 2024 · 6 comments
Assignees
Labels
type: bug Something isn't working type: regression A breaking change was introduced in a minor or patch release

Comments

@salih
Copy link

salih commented Oct 7, 2024

Expected Behavior

Previously was running on Micronaut 4.4.2 and when an invalid JSON payload such as below is provided, Micronaut would throw io.micronaut.json.JsonSyntaxException and we could handle this with a global exception handler.

curl --location 'http://localhost:8080/test' \
--header 'Content-Type: application/json' \
--data '{
    invalid
}'

Actual Behaviour

On Micronaut 4.6.2, instead io.micronaut.core.convert.exceptions.ConversionErrorException is being thrown.

Steps To Reproduce

  1. Clone the repository https://github.com/salih/micronaut-bug-october-24/
  2. Execute ./gradlew run
  3. Send an invalid payload to the demo endpoint
curl --location 'http://localhost:8080/test' \
--header 'Content-Type: application/json' \
--data '{
    invalid
}'

You will have seen that the global exception handler in DemoController will kick in and handle ConversionException which controller will respond with message
ConversionException is thrown
4. Edit gradle.properties and change 1st line to downgrade to Micronaut version to 4.4.2
micronautVersion=4.4.2 and save
5. Repeat steps 2 and 3 to run the service with the older version of Micronaut
6. You will have seen that the output is different
JsonSyntaxException is thrown

Environment Information

macOS Sonoma 14.7 BuildVersion: 23H124
Gradle 8.8
Kotlin: 1.9.22
Groovy: 3.0.21
Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM: 17.0.12 (Amazon.com Inc. 17.0.12+7-LTS)
OS: Mac OS X 14.7 aarch64

Example Application

https://github.com/salih/micronaut-bug-october-24/

Version

4.6.2

@graemerocher graemerocher added the type: bug Something isn't working label Oct 7, 2024
@graemerocher graemerocher added the type: regression A breaking change was introduced in a minor or patch release label Oct 7, 2024
@graemerocher
Copy link
Contributor

@yawkat can you have a look at this one

@yawkat
Copy link
Member

yawkat commented Oct 7, 2024

If you want the old behavior you can switch to micronaut-jackson-databind. We switched the default serialization framework in 4.0.

@yawkat yawkat closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2024
@salih
Copy link
Author

salih commented Oct 7, 2024

If you want the old behavior you can switch to micronaut-jackson-databind. We switched the default serialization framework in 4.0.

@yawkat I'm not sure how this applies, the previous version was already on 4.x.x (4.4.2 to be precise) and this was introduced after upgrading to 4.6.2 so essentially we aren't upgrading from 3.x to 4.x?

@graemerocher
Copy link
Contributor

@yawkat why is there a difference in behaviour between Jackson and Micronaut Serialization here since the exception is io.micronaut.json.JsonSyntaxException? There shouldn't be a difference in behaviour

@yawkat
Copy link
Member

yawkat commented Oct 7, 2024

Ahh I thought this was an upgrade from 3.6.2, given the version at the bottom. I'll take another look.

@yawkat yawkat reopened this Oct 7, 2024
@salih
Copy link
Author

salih commented Oct 7, 2024

My bad, sorry about the discrepancy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working type: regression A breaking change was introduced in a minor or patch release
Projects
Status: Done
Development

No branches or pull requests

3 participants