Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
Can't parse Map<String, Double> with Moshi in Kotlin - Unexpected primitive double
val moshi = Moshi.Builder().build()
val type = Types.newParameterizedType(Map::class.java, String::class.java, Double::class.java)
val adapter = moshi.adapter<Map<String, Double>>(type)

val result = adapter.fromJson(InitData.json)

just switching from Gson to Moshi and i ran into this problem. I expect above code to work since it seems to work fine with Map<String, String>.

I'm getting an IllegalArgumentException: Unexpected primitive double. Use the boxed type

Same thing for Float. I know what's happening here but is this not possible with Moshi?

This is using com.squareup.moshi:moshi-kotlin:1.8.0

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Use Types.newParameterizedType(Map::class.java, String::class.java, Double::class.javaObjectType)

javaOjectType returns the corresponding boxed type for primitive types.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!