com.fasterxml.jackson.module.kotlin.UnsignedNumbers.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-module-kotlin Show documentation
Show all versions of jackson-module-kotlin Show documentation
Add-on module for Jackson (https://github.com/FasterXML/jackson/) to support
Kotlin language, specifically introspection of method/constructor parameter names,
without having to add explicit property name annotation.
package com.fasterxml.jackson.module.kotlin
import java.math.BigInteger
fun Short.asUByte() = when {
this >= 0 && this <= UByte.MAX_VALUE.toShort() -> this.toUByte()
else -> null
}
fun Int.asUShort() = when {
this >= 0 && this <= UShort.MAX_VALUE.toInt() -> this.toUShort()
else -> null
}
fun Long.asUInt() = when {
this >= 0 && this <= UInt.MAX_VALUE.toLong() -> this.toUInt()
else -> null
}
private val uLongMaxValue = BigInteger(ULong.MAX_VALUE.toString())
fun BigInteger.asULong() = when {
this >= BigInteger.ZERO && this <= uLongMaxValue -> this.toLong().toULong()
else -> null
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy