corda / net.corda.client.jackson / StringToMethodCallParser / <init>

<init>

StringToMethodCallParser(targetType: KClass<out T>)

Same as the regular constructor but takes a Kotlin reflection KClass instead of a Java Class.

StringToMethodCallParser(targetType: Class<out T>, om: ObjectMapper = JacksonSupport.createNonRpcMapper(YAMLFactory()))

This class parses strings in a format designed for human usability into ParsedMethodCall objects representing a ready-to-invoke call on the given target object. 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 the Corda shell, text-based RPC dispatch, simple scripting and so on.

Syntax

The format of the string is as follows. The first word is the name of the method and must always be present. The rest, which is 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 parameters of the method via the usual Jackson mechanisms. The standard java.lang.Object methods are excluded.

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

    fun someCall(note: String, option: Boolean)

    someCall note: This is a really helpful feature, option: true

... 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, and the resulting ParsedMethodCall objects may be reused multiple times and also invoked in parallel, as long as the underling target object is thread safe itself.

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

Examples

    fun simple() = ...
    "simple"   -> runs the no-args function 'simple'

    fun attachmentExists(id: SecureHash): Boolean
    "attachmentExists id: b6d7e826e87"  -> parses the given ID as a SecureHash

    fun addNote(id: SecureHash, note: String)
    "addNote id: b6d7e826e8739ab2eb6e077fc4fba9b04fb880bb4cbd09bc618d30234a8827a4, note: Some note"