Convert a CborValue into a JsonValue if there is an equivalent JsonValue; otherwise return a Left containing the incompatible value
Convert a CborValue into a JsonValue if there is an equivalent JsonValue; otherwise return a Left containing the incompatible value
// Declaring the failure to convert, with no attempts to post-fix val cbor:CborValue = ??? val jsonEither = JsonValue.cborValue2JsonValueEither(cbor).fold( {x => BuilderFailure(TypeCoercionFailure, ())}, {x => Complex(x)} )
// With attempts to convert the incompatible values to something that will fit into a JsonValue import java.nio.charset.StandardCharsets.US_ASCII; val cbor:CborValue = ??? val json:JsonValue = JsonValue.cborValue2JsonValueEither(cbor).fold( {_.fold( // in this example, base64-encode any ByteStrings {x => JsonValueString(new String(java.util.Base64.getEncoder.encode(x), US_ASCII))}, // in this example, convert infinite values and nan to null, and round any other value {x => x match { case Rational.NaN => JsonValueNull case Rational.PositiveInfinity => JsonValueNull case Rational.NegativeInfinity => JsonValueNull case x => x.toDouble }} )}, {x => x} )
3.1
Allows implicit conversions from Int or Double directly to JsonValue
Allows implicit conversions from Int or Double directly to JsonValue
3.1
Convert a StringOrInt value into a JsonValue
Convert a CborValue into a JsonValue, where ByteStrs are instead converted into hexencoded strings.
Convert a CborValue into a JsonValue, where ByteStrs are instead converted into hexencoded strings.
(Since version 3.1) doesn't handle incompatible numbers; use cborValue2JsonValueEither then fold that method's return value
The cases of JsonValue and methods to convert other things into JsonValues.
3.0