StringToClassParser

class StringToClassParser<T>(val 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.

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

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

  • The target class must be either a Kotlin class, or a Java class conforming to standard design patterns to identify property accessors (see java.beans.Introspector

Constructors

Link copied to clipboard
constructor(targetType: Class<T>)

Types

Link copied to clipboard
open class MappingException(message: String, cause: Throwable? = null)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun parse(input: String, mapper: <Error class: unknown class>): <Error class: unknown class><T>

Converts a given input parameters into instance of given type