powered by ASAP

1. What you will learn

In this short summary you will get an idea on where and how the IJsonMapper interface is used.

2. Basics

All data which is loaded during the execution of an engine will be tried to be converted to JSON before being delegated to interpreters. The IJsonMapper is responsible for all of those conversions.

3. Signature

Before giving a short example on how the interface should be used, this section describes the signature of the IJsonMapper interface, as well as an overview on which methods have to be implemented.

<T> T toBean(final String json, final Type toClass);

Converts the given json string into its object representation of the given type.

<T> T toBean(final String json, final Class<T> toClass);

Analogous to the method above, but takes a java class as the type.

String toJsonString(final Object bean);

Converts a given bean into a json string.

String resolvePathIn(final String json, final String... path);

Resolves the given json path inside the given json.

boolean isJson(final Object bean);

Checks if the given bean is a JSON String.

JsonType jsonType(final Object bean);

enum JsonType {
    NONE, NULL, STRING, PRIMITIVE, OBJECT, ARRAY
}

Checks the given bean for it’s json type.

resolvePathIn() should at least support the JSON path syntax defined in the Interpolation Reference

4. Usage in the Engine

This section briefly outlines how the IJsonMapper will be used in the engine.

4.1. Engine Persistence

When the engine tries to store a value to the datastore (store), it will convert the object to the JSON format using toJsonString() before converting the value to the user scheme in the IDataTransformer

4.2. Interpreters

As interpreters only have access to the value in JSON format, they will use the IJsonMapper for their internal processing if necessary. In PAK, jlcint as well as the Human Task interpreter will use the interface to perform conversions to java values.

5. Default Implementations

  • The de.asap.pak.extra.impl.datatransformer.ObjectMapperFacade: Implementation using Jackson