Skip to content

Wrong gson deserialization of list of integers #18397

Closed
@tgodzik

Description

@tgodzik

Compiler version

3.3.0

Minimized code

//> using dep com.google.code.gson:gson:2.10.1
//> using scala 3.3.0

import com.google.gson.Gson
import scala.jdk.CollectionConverters._

case class HasArray(
    argIndices: java.util.List[Integer]
)

object Main {

  def main(args: Array[String]): Unit = {
    val gson = new Gson();
    val arr =
      gson.fromJson[HasArray]("{ \"argIndices\" : [1,2,3]}", classOf[HasArray])
    println(arr.argIndices)
  }
}

Output

[1.0, 2.0, 3.0]

the elements in the list are actually Doubles.

Expectation

[1, 2, 3]

This worked ok in the previous Scala versions 2.13.x.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions