Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

300
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda