Is it possible to serialize a generic Map<String, Any> in JVM/JS as a JSON object?
See original GitHub issueI’m trying to figure out a way to serialize an arbitrary Map<String, Any>
into JSON. In my case, I can guarantee that in runtime any value of the map is either a primitive, a list or a map. In case of lists and maps, the values of them are either primitives or lists or maps of the same pattern. Seems, it lays nicely on a json object.
I do not need to deserialize such an object, serialization only.
For now, I’m trying to write a custom serializer for such case but no success yet. How can it be done for both JVM and JS?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:18 (3 by maintainers)
Top Results From Across the Web
Parse a JSON array into Map<String, String> using Kotlinx ...
So far, I am able to get that JSON as String, but I can't find any documentation to help me build a Map...
Read more >Map Serialization and Deserialization with Jackson - Baeldung
A quick and practical guide to serializing and deserializing Java Maps using Jackson.
Read more >Serialize a Map into a specific JSON object
Here how you can achieve it. map<string, object> mapToSerialize = new map<string, object>(); mapToSerialize.put('type', 'TEST'); //add you ...
Read more >How to serialize properties of derived classes with System ...
In this article, you will learn how to serialize properties of derived classes with the System.Text.Json namespace.
Read more >JSON Serialization Usage
Flexjson is a lightweight library for serializing and deserializing Java objects into and from JSON. What's different about Flexjson is it's control over ......
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 FreeTop 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
Top GitHub Comments
Its about converting Any to JsonElement, not the other way around. Any isnt very type-safe but provides a big use case with Maps. As with other serializers it would just thrown an JsonException on unsupported types.
@hotchemi You can replace
Map
type withJsonObject