corda / net.corda.client.jackson / StringToClassParser

StringToClassParser

class StringToClassParser<T>

This class parses strings in a format designed for human usability into objects usually to support representation of a query object pattern. The strings accepted by this class are a minor variant of Yaml and can be easily typed at a command line. Intended use cases include things like queries in the Corda shell.

Syntax

The format of the string is as follows. The string, which is can be optional, is wrapped in curly braces and parsed as if it were a Yaml object. The keys of this object are then mapped to the class properties via the usual Jackson mechanisms.

One convenient feature of Yaml is that bare words collapse into strings, thus you can write a call like the following:

    data class(val note: String, val option: Boolean, val sources: List<SUSPENSION_SOURCE>

    note: This is a really helpful feature, option: true, sources: [SEND, RECEIVE]

... and it will be parsed in the intuitive way. Quotes are only needed if you want to put a comma into the string.

There is an online Yaml parser which can be used to explore the allowed syntax.

Usage

This class is thread safe. Multiple strings may be parsed in parallel.

You may pass in an alternative ObjectMapper to control what types can be parsed, but it must be configured with the YAMLFactory for the class to work.

Limitations

Types

MappingException

class MappingException

Constructors

<init>

StringToClassParser(targetType: Class<T>)

This class parses strings in a format designed for human usability into objects usually to support representation of a query object pattern. The strings accepted by this class are a minor variant of Yaml and can be easily typed at a command line. Intended use cases include things like queries in the Corda shell.

Properties

targetType

val targetType: Class<T>

Functions

parse

fun parse(input: String, mapper: <ERROR CLASS>): <ERROR CLASS><T>

Converts a given input parameters into instance of given type