How to Deserialize java.util.ArrayList from Scala


We have a Java object, in my case java.util.ArrayList of strings, serialized with native Java serializer and base-64 encoded. I need to get out the array of strings in Scala.


import java.util.{ArrayList, Base64}

val arrayListString = "rO0..."

// get data bytes from base-64 encoded string
val arBytes = Base64.getDecoder.decode(arrayListString)

// use standard Java object serializer
val arOis = new ObjectInputStream(new ByteArrayInputStream(arBytes))

val arDes = arOis.readObject().asInstanceOf[ArrayList[String]]

To contact me, send an email anytime or leave a comment below.