parseAs

inline fun <T : YsonValue> parseAs(yson: String): T

parseAs parses a YSON formatted string and narrows the result to T.

Mirrors the generic type parameter of parse<T extends YSONValue>(...) in yorkie-js-sdk. The reified type T is checked at runtime against the parsed root value; a mismatch surfaces as a YorkieException rather than a ClassCastException.

val obj = parseAs<YsonValue.YsonObject>("""{"content":Text([{"val":"Hi"}])}""")
val text = obj.entries["content"] as YsonValue.YsonText

Parameters

yson

YSON formatted string.

Throws

with YorkieException.Code.ErrInvalidArgument when parsing fails or the parsed root is not an instance of T.