Add concerte type for JsonPrimitives
See original GitHub issueWhat 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:
- Created 3 years ago
- Reactions:7
- Comments:8 (3 by maintainers)
Top 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 >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
Just ran into this problem. I am parsing user input in the form of
String
toJsonElement
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.
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