ObjectPath Class

  • java.lang.Object
    • com.microsoft.bot.dialogs.ObjectPath

public final class ObjectPath

Helper methods for working with dynamic json objects.

Method Summary

Modifier and Type Method and Description
static T <T>assign(T startObject, Object overlayObject)

Equivalent to javascripts ObjectPath.Assign, creates a new Object from startObject overlaying any non-null values from the overlay Object.

static T <T>assign(Object startObject, Object overlayObject, Class<T> type)

Equivalent to javascripts ObjectPath.Assign, creates a new Object from startObject overlaying any non-null values from the overlay Object.

static T <T>clone(T obj)

Clone an Object.

static T <T>getPathValue(Object obj, String path, Class<T> valueType)

Get the value for a path relative to an Object.

static T <T>getPathValue(Object obj, String path, Class<T> valueType, T defaultValue)

Get the value for a path relative to an Object.

static T <T>mapValueTo(Object val, Class<T> valueType)

Convert a generic Object to a typed Object.

static T <T>merge(Object startObject, Object overlayObject)

Equivalent to javascripts ObjectPath.Assign, creates a new Object from startObject overlaying any non-null values from the overlay Object.

static T <T>merge(Object startObject, Object overlayObject, Class<T> type)

Equivalent to javascripts ObjectPath.Assign, creates a new Object from startObject overlaying any non-null values from the overlay Object.

static T <T>tryGetPathValue(Object obj, String path, Class<T> valueType)

Get the value for a path relative to an Object.

static com.microsoft.bot.dialogs.Segments <T>tryResolvePath(Object obj, String propertyPath)

Given an root Object and property path, resolve to a constant if eval = true or a constant path otherwise.

static com.microsoft.bot.dialogs.Segments <T>tryResolvePath(Object obj, String propertyPath, boolean eval)

Given an root Object and property path, resolve to a constant if eval = true or a constant path otherwise.

static boolean containsProperty(Object obj, String name)

Detects if property exists on Object.

static void forEachProperty(Object obj, BiConsumer<String,Object> action)

Apply an action to all properties in an Object.

static java.util.Collection<java.lang.String> getProperties(Object obj)

Get all properties in an Object.

static boolean hasValue(Object obj, String path)

Does an Object have a subpath.

static void removePathValue(Object obj, String path)

Remove path from Object.

static void setPathValue(Object obj, String path, Object value)

Given an Object evaluate a path to set the value.

static void setPathValue(Object obj, String path, Object value, boolean json)

Given an Object evaluate a path to set the value.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Method Details

<T>assign

public static T assign(T startObject, Object overlayObject)

Equivalent to javascripts ObjectPath.Assign, creates a new Object from startObject overlaying any non-null values from the overlay Object.

Parameters:

startObject - overlay Object of any type.
overlayObject - overlay Object of any type.

Returns:

merged Object.

<T>assign

public static T assign(Object startObject, Object overlayObject, Class type)

Equivalent to javascripts ObjectPath.Assign, creates a new Object from startObject overlaying any non-null values from the overlay Object.

Parameters:

startObject - intial Object of any type.
overlayObject - overlay Object of any type.
type - type to output.

Returns:

merged Object.

<T>clone

public static T clone(T obj)

Clone an Object.

Parameters:

obj - The Object.

Returns:

The Object as Json.

<T>getPathValue

public static T getPathValue(Object obj, String path, Class valueType)

Get the value for a path relative to an Object.

Parameters:

obj - Object to start with.
path - path to evaluate.
valueType - Type of T

Returns:

value or default(T).

<T>getPathValue

public static T getPathValue(Object obj, String path, Class valueType, T defaultValue)

Get the value for a path relative to an Object.

Parameters:

obj - Object to start with.
path - path to evaluate.
valueType - type of T
defaultValue - default value to use if any part of the path is missing.

Returns:

value or default(T).

<T>mapValueTo

public static T mapValueTo(Object val, Class valueType)

Convert a generic Object to a typed Object.

Parameters:

val - value to convert.
valueType - Type of T

Returns:

converted value.

<T>merge

public static T merge(Object startObject, Object overlayObject)

Equivalent to javascripts ObjectPath.Assign, creates a new Object from startObject overlaying any non-null values from the overlay Object.

Parameters:

startObject - Intial Object.
overlayObject - Overlay Object.

Returns:

merged Object.

<T>merge

public static T merge(Object startObject, Object overlayObject, Class type)

Equivalent to javascripts ObjectPath.Assign, creates a new Object from startObject overlaying any non-null values from the overlay Object.

Parameters:

startObject - Intial Object.
overlayObject - Overlay Object.
type - Type of T

Returns:

merged Object.

<T>tryGetPathValue

public static T tryGetPathValue(Object obj, String path, Class valueType)

Get the value for a path relative to an Object.

Parameters:

obj - Object to start with.
path - path to evaluate.
valueType - value for the path.

Returns:

true if successful.

<T>tryResolvePath

public static Segments tryResolvePath(Object obj, String propertyPath)

Given an root Object and property path, resolve to a constant if eval = true or a constant path otherwise. conversation[user.name][user.age] to ['conversation', 'joe', 32].

Parameters:

obj - root Object.
propertyPath - property path to resolve.

Returns:

True if it was able to resolve all nested references.

<T>tryResolvePath

public static Segments tryResolvePath(Object obj, String propertyPath, boolean eval)

Given an root Object and property path, resolve to a constant if eval = true or a constant path otherwise. conversation[user.name][user.age] to ['conversation', 'joe', 32].

Parameters:

obj - root Object.
propertyPath - property path to resolve.
eval - True to evaluate resulting segments.

Returns:

True if it was able to resolve all nested references.

containsProperty

public static boolean containsProperty(Object obj, String name)

Detects if property exists on Object.

Parameters:

obj - Object.
name - name of the property.

Returns:

true if found.

forEachProperty

public static void forEachProperty(Object obj, BiConsumer action)

Apply an action to all properties in an Object.

Parameters:

obj - Object to map against.
action - Action to take.

getProperties

public static Collection getProperties(Object obj)

Get all properties in an Object.

Parameters:

obj - Object to enumerate property names.

Returns:

enumeration of property names on the Object if it is not a value type.

hasValue

public static boolean hasValue(Object obj, String path)

Does an Object have a subpath.

Parameters:

obj - Object.
path - path to evaluate.

Returns:

true if the path is there.

removePathValue

public static void removePathValue(Object obj, String path)

Remove path from Object.

Parameters:

obj - Object to change.
path - Path to remove.

setPathValue

public static void setPathValue(Object obj, String path, Object value)

Given an Object evaluate a path to set the value.

Parameters:

obj - Object to start with.
path - path to evaluate.
value - value to store.

setPathValue

public static void setPathValue(Object obj, String path, Object value, boolean json)

Given an Object evaluate a path to set the value.

Parameters:

obj - Object to start with.
path - path to evaluate.
value - value to store.
json - if true, sets the value as primitive JSON Objects.

Applies to