public interface Dynamic extends Weak<Dynamic>
{
"product": {
"investment": {
"info": {
"current": {
"name": "some name"
}
}
}
}
}
We can select the nested 'name' field with
Dynamic.from(message).dget("product.investment.info.current.name").asString()| Modifier and Type | Field and Description |
|---|---|
static String |
ROOT_KEY
Default key value for top-level Dynamic instances
|
| Modifier and Type | Method and Description |
|---|---|
default Stream<Dynamic> |
allChildren() |
default Stream<Dynamic> |
allChildrenBreadthFirst()
Returns a stream of all children in a breadth first order, for example a structure
|
default Stream<Dynamic> |
allChildrenDepthFirst()
Returns a stream of all children in a depth first order, for example a structure
|
default <T> T |
as(Class<T> type)
As
Weak.asObject() casting to input type, and providing a better message in the exceptional case |
Stream<Dynamic> |
children() |
default Dynamic |
dget(String dotSeparatedPath)
Shortcut for
dynamic.get("some.path.to.somewhere", ".") avoiding the need for the second argument
ie dynamic.dget("some.path.to.somewhere") |
static Dynamic |
from(Object val)
Wraps a value in a dynamic representation, properly handled nested types are Maps & Collections all other types
become dynamic end-points.
|
Dynamic |
get(Object key)
Returns a dynamic wrapping the immediate child of this instance with the input key,
or a dynamic representing the lack of such a child.
|
default Dynamic |
get(String keyPath,
String separator)
Performs multiple String gets as described by an input key path
so
dynamic.get("one.two.three", ".")
is equivalent to dynamic.get("one").get("two").get("three") |
Weak<?> |
key()
Returns Weak instance wrapping the key for this node.
|
static final String ROOT_KEY
static Dynamic from(Object val)
Converter to perform simple conversions to these types where applicable
See XmlDynamic for an XML handling dynamic representationval - some valueDynamic get(Object key)
key - child keydefault Dynamic get(String keyPath, String separator)
dynamic.get("one.two.three", ".")
is equivalent to dynamic.get("one").get("two").get("three")keyPath - successive child keys separated by separator stringseparator - a string separator to split the input key input multiple keysdefault Dynamic dget(String dotSeparatedPath)
dynamic.get("some.path.to.somewhere", ".") avoiding the need for the second argument
ie dynamic.dget("some.path.to.somewhere")dotSeparatedPath - successive child keys separated by "." characterWeak<?> key()
Weak.asObject()
Top-level Dynamic objects have the key value ROOT_KEYdefault Stream<Dynamic> allChildren()
allChildrenDepthFirst()default Stream<Dynamic> allChildrenDepthFirst()
services:
service1:
name: service one
service2:
name: service two
services.allChildrenDepthFirst() would produce a stream ordered
[service1, service1.name, service2, service2.name]
As such depth first searching can be implemented, for example
services.allChildrenDepthFirst()
.filter(child -> child.isString() && child.asString().equals("service one"))
.findAny(); // Optional[Dynamic: service1.name]
default Stream<Dynamic> allChildrenBreadthFirst()
services:
service1:
name: service one
service2:
name: service two
services.allChildrenDepthFirst() would produce a stream ordered
[service1, service2, service1.name, service2.name]
As such breadth first searching can be implemented, for example
services.allChildrenBreadthFirst()
.anyMatch(child -> child.key().asString().equals("service2")); // true
default <T> T as(Class<T> type)
Weak.asObject() casting to input type, and providing a better message in the exceptional caseas in interface Weak<Dynamic>T - cast typetype - cast typeClassCastException - when the wrapped instance that cannot be cast to the inputNoSuchElementException - when this dynamic is not present, ie wraps no, or null, valueCopyright © 2017. All rights reserved.