korlibs / korlibs/korlibs-serialization

Long serialization issue

Open
#5 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
0
Forks
1
PR merge metrics
No merged PRs in 30d

Description

@Serializable
class DoubleVal(val doubleVal: Long)

@Test
fun testDouble(){
val str = """{"doubleVal":1725255546765}"""
val korlibsJson = KJson.parse(str)
val korlibsStr = KJson.stringify(korlibsJson)
println(korlibsStr) //{"doubleVal":1.725255546765E12}
}

I have a use case where I use kotlinx serialisation to create class object from json and vice versa. I use both kotlinx serialisation and korlibs json to achieve my use case. Now in above case, I create a string with a long value, but by default korlibs serialises it to a double. This causes issue when I again serialise it with kotlinx serialisation as my defined type would be long. (As it is represented as scientific notation and has a decimal, it is treated as double by default)

I am not sure if this is fine, and kotlinx lib should be able to handle it(I don't think coz typecasting from double to long does not seem feasible). Please kindly advise on this

Also, the reason I use both libraries is, I use kotlinx for creating class objects from json. I use korlibs when I want to manipulate a json directly. Manipulating a kotlinx json is painful. It made the code unmaintable and bug prone.
In certain cases I have to manipulate the json before it is serialized to ensure errorless serialization
Let me know if I miss something or misunderstood something

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the testDouble example in the issue and inspect KJson.parse and KJson.stringify behavior for the Long value 1725255546765. Compare the resulting output with kotlinx serialization expectations; the issue is complete only when the intended numeric representation and compatibility behavior are defined and covered by a test.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.