-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to parse int in my data class #332
Comments
I have the same issue. I got this error from every type of JSON field. |
You have to use null safe type, eg. Int? |
I have a similar issue: Exception in thread "main" com.beust.klaxon.KlaxonException: Unable to instantiate GeoCoordinates:
Parameter latitudeInDecDeg: expected kotlin.Float but received java.lang.Float (value: 70.0)
Parameter longitudeInDecDeg: expected kotlin.Float but received java.lang.Float (value: 70.0)
Parameter latLongResolutionInDp: expected kotlin.Int but received java.lang.Integer (value: 0) This is my data class: data class GeoCoordinates(val latitudeInDecDeg: Float, val longitudeInDecDeg: Float, val latLongResolutionInDp: Int = 4) |
@cbeust Could you please help with this ? Why is Klaxon picking up the Java types as default. Are we all making a silly mistake here ? |
use null safe type: |
Ah, no it is not that. My data class has data validation in the |
Yes, I also had that error, I just declare the variable with null-safe type then the error goes away. |
In my data calss, I have a field quantity defined as below:
val quantity : Int
in the json it looks like:
"quantity" : 3
When I run the code I got the exception
After this i undersstood the problem is with my data type, and the library by default cast the values into java data type, so I change it to java.lang.Integer.
val quantity : Integer
even this dosn't helped and still I'm facing the same error with
java.lang.Integer.
Since in the JSON the type of keys are not defined the library should cast based on the data class variable just like GSON and Jackson library do.
The text was updated successfully, but these errors were encountered: