Unable to use GSON to serialize anonymous class
See original GitHub issueActual behavior (the bug)
When attempting to configure Javalin to utilize Gson instead of Jackson for JSON serialization/deserialization, instead of having the configured JSON response body being generated, I receive the string null
.
Expected behavior I would expect to see the configured JSON response.
To Reproduce Use the https://github.com/Jitsusama/javalin-gson-example repository as an example. Run the single test in the single class defined in that project and you’ll see what I mean.
Additional context My example project has DEBUG logging turned on by default in case it helps with diagnosis. Attached is an example log. The most pertinent entries from the log are as so:
Request method: GET
Request URI: http://localhost:8888
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Accept=*/*
Cookies: <none>
Multiparts: <none>
Body: <none>
HTTP/1.1 500 Server Error
Date: Thu, 12 Jul 2018 11:52:17 GMT
Server: Javalin
Content-Type: application/x.my.custom.error+json
Content-Length: 4
null
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Serializing anonymous classes with Gson - java - Stack Overflow
1 Answer 1 ... Gson can also deserialize static nested classes. However, Gson can not automatically deserialize the pure inner classes since their...
Read more >Unable to use GSON to serialize anonymous class · Issue #288
Actual behavior (the bug) When attempting to configure Javalin to utilize Gson instead of Jackson for JSON serialization/deserialization, ...
Read more >Gson User Guide - Google Sites
Gson can work with arbitrary Java objects including pre-existing objects that you ... However, Gson can not automatically deserialize the pure inner classes...
Read more >Serializing and Deserializing a List with Gson - Baeldung
In this tutorial, we'll explore a few advanced serialization and deserialization cases for List using Google's Gson library.
Read more >Deserialization problem - Google Groups
I have no problem serializing. I can deserialize using json-lib (net.sf.json.JSONSerializer.toJSON) but not using gson. //create a list of myObect's
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s possible I’m just stupid, but also, it might be possible that some other user could get bitten by this issue. Would you mind if I put through a PR to update the documentation example for Gson integration to call out this scenario?
You’re welcome. If you really hate dependencies and need a simple
mapOf
method, you can useTemplateUtil.model()
: