Other Enumerations
The following enumerations are available globally.
-
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
nilfor invalid or non-representable values rather than crashing or producing corrupted data.Edge cases handled:
- Integer overflow: NaN values return
nil; values outsideInt.min...Int.max(including infinities) are clamped toInt.min/Int.max - Special float values:
Double.nanis treated as invalid;Double.infinityand-Double.infinityare clamped in integer conversions - String parsing: Invalid formats return
nilrather than crashing - Type mismatches: Missing or incompatible types return
nil
Example usage:
See morelet payload: DataObject = ... let timeout = payload.getConvertible(key: "timeout", converter: LenientConverters.double) let retryCount = payload.getConvertible(key: "retryCount", converter: LenientConverters.int) let isEnabled = payload.getConvertible(key: "isEnabled", converter: LenientConverters.bool)Declaration
Swift
public enum LenientConverters - Integer overflow: NaN values return
View on GitHub
Other Enumerations Reference