question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to serialize a generic Map<String, Any> in JVM/JS as a JSON object?

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:18 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
dri94commented, Feb 21, 2019

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.

14reactions
sandwwraithcommented, Jan 31, 2019

@hotchemi You can replace Map type with JsonObject

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found