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.

Add concerte type for JsonPrimitives

See original GitHub issue

What is your use-case and why do you need this feature?

I found its very complex when I try to parse the json string when the type is unknown, for example, I cannot decode json to Map<String, Any?> except Map<String, JsonElement>, because I shouldn’t expose JsonElement to caller, so I try to parse them manually and I cannot get real type of JsonPrimitive, the Api only provide some converter method and isString to determine whether it is a String, even if I can detect and parse the string to real type just like Int, Float, Boolean … it’s not very convenient.

Describe the solution you’d like

add a way to determine the real type of JsonPrimitive or just parse them as Any like other json parse library.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:7
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
gnawfcommented, Apr 29, 2022

Just ran into this problem. I am parsing user input in the form of String to JsonElement to put as JWT claims (for a HTTP Client). I need to put Kotlin/Java primitives i.e. Int, String, Double, Map, List as arguments into the claims object.

This is a solved problem in Gson and Jackson but I was hoping to use a Kotlin 1st solution for sealed classes etc… Guess not.

2reactions
sandwwraithcommented, Dec 20, 2021

However, it is still possible to handle booleans there separately, so users can easily differentiate whether it is String, Boolean, Null, or Number. While we still do not aim to provide a number-parsing strategy, differentiating of booleans may help in some use-cases

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert interface{} from JSON to one of multiple concrete types
After I've unmarshaled the json bytes to an interface{} , how can I convert it to a concrete type? If it fails, I...
Read more >
C# serialization with JsonSchema and System.Text.Json
This involves mapping from the document into concrete C# types. ... JSON defines a small number of value primitives:.
Read more >
How to write custom converters for JSON serialization - .NET
Learn how to create custom converters for the JSON serialization classes that are provided in the System.Text.Json namespace.
Read more >
JSON.simple - Quick Guide - Tutorialspoint
Using JSONValue object, we can create a JSON which comprises of primitives, Object, Map and List. Following example illustrates the above concept. Example....
Read more >
Deserializing JSON into polymorphic classes with System.Text ...
In this post, I'll explain how to write a custom JsonConverter for System.Text.Json to help with deserialization for such cases.
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