Target filter
Search Kotlin docs
  • Platforms
  • Tealium Prism Kotlin
core/com.tealium.prism.core.api.data/LenientConverters

LenientConverters

object LenientConverters

A collection of lenient converters that can handle type mismatches in JSON data.

These converters attempt multiple conversion strategies when the actual type in JSON differs from the expected type. They follow a fail-safe pattern: returning null for invalid or non-representable values rather than crashing or producing corrupted data.

Edge cases handled:

  • Int/Long overflow: NaN values return null; values outside Int.MIN_VALUE..Int.MAX_VALUE or Long.MIN_VALUE..Long.MAX_VALUE (including infinities) are clamped to their respective max and min values

  • Special float values: Double.NaN is treated as invalid for Int/Long converters; Double.POSITIVE_INFINITY and Double.NEGATIVE_INFINITY are clamped in integer max and min values

  • String parsing: Invalid formats return null rather than crashing

  • Type mismatches: Missing or incompatible types return null

Example usage:

val payload: DataObject = ...
val timeout = payload.get("timeout", LenientConverters.DOUBLE)
val retryCount = payload.get("retryCount", LenientConverters.INT)
val isEnabled = payload.get("isEnabled", LenientConverters.BOOLEAN)
Content copied to clipboard

Properties

BOOLEAN
Link copied to clipboard
val BOOLEAN: DataItemConverter<Boolean>

A lenient converter to Boolean values.

DOUBLE
Link copied to clipboard
val DOUBLE: DataItemConverter<Double>

A lenient converter to Double values.

INT
Link copied to clipboard
val INT: DataItemConverter<Int>

A lenient converter to Int values.

LONG
Link copied to clipboard
val LONG: DataItemConverter<Long>

A lenient converter to Long values.

STRING
Link copied to clipboard
val STRING: DataItemConverter<String>

A lenient converter to String values.

Generated by Dokka
(c) Tealium 2026