All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fasterxml.jackson.module.kotlin.UnsignedNumbers.kt Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 2.18.2
Show newest version
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