za.co.absa.shaded.jackson.module.scala.BitSetDeserializerModule.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of absa-shaded-jackson-module-scala_3 Show documentation
Show all versions of absa-shaded-jackson-module-scala_3 Show documentation
absa-shaded-jackson-module-scala
The newest version!
package za.co.absa.shaded.jackson.module.scala
import za.co.absa.shaded.jackson.databind.{BeanDescription, DeserializationConfig, JavaType, JsonDeserializer}
import za.co.absa.shaded.jackson.databind.deser.Deserializers
import za.co.absa.shaded.jackson.module.scala.deser.{ImmutableBitSetDeserializer, MutableBitSetDeserializer}
import scala.collection.{BitSet, immutable, mutable}
/**
* Adds support for deserializing Scala [[scala.collection.BitSet]]s. Scala Bitsets can already be
* serialized using [[IteratorModule]] or [[DefaultScalaModule]].
*
* Do not enable this module unless you are sure that no input is accepted from untrusted sources.
*
* Scala BitSets use memory based on the highest int value stored. So a BitSet with just one big int will use a lot
* more memory than a Scala BitSet with many small ints stored in it.
*
* @since 2.14.0
*/
object BitSetDeserializerModule extends JacksonModule {
override def getModuleName: String = "BitSetDeserializerModule"
this += (_ addDeserializers new Deserializers.Base {
private val IMMUTABLE_BITSET_CLASS: Class[_] = classOf[immutable.BitSet]
private val MUTABLE_BITSET_CLASS: Class[_] = classOf[mutable.BitSet]
override def findBeanDeserializer(javaType: JavaType, config: DeserializationConfig, beanDesc: BeanDescription): JsonDeserializer[BitSet] = {
val rawClass = javaType.getRawClass
if (IMMUTABLE_BITSET_CLASS.isAssignableFrom(rawClass)) {
ImmutableBitSetDeserializer.asInstanceOf[JsonDeserializer[BitSet]]
} else if (MUTABLE_BITSET_CLASS.isAssignableFrom(rawClass)) {
MutableBitSetDeserializer.asInstanceOf[JsonDeserializer[BitSet]]
} else {
None.orNull
}
}
})
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy