public class Dynamic extends Object
Dynamic Values
An object is a dynamic value if its graph contains only:
Value Copies
This factory takes an arbitrary object graph and returns its value copy (valueOf(Object)), i.e. a
"copy" in which:
Iterable types are replaced with dynamic lists;
External Value Copies
This factory can also produce external value copies (externalValueOf(Object), where dynamic lists
and dynamic values are appropriately wrapped exclusively for JAXB serialisation. For this purpose, DynamicIO
offers a JAXBContext pre-configured with wrapper classes:
MyObject o = ... JAXBContext context = DynamicIO.newInstance(); context.createMarshaller().marshal(Dynamic.externalValueOf(o),...sink...);Deserialisation proceeds similarly, and
valueOf(Object) can be invoked on the deserialised object to unwrap
the external value copy into a normal value copy for further processing:
JAXBContext context = DynamicIO.newInstance(); Object externalValue = context.createUnmarshaller().unmarshal(...source...); Object value = valueOf(externalvalue); ...process value...
Assignments and Casts
valueOf(Object) and externalValueOf(Object) can be applied to any object, including lists, maps,
wrapper types (hence primitive values, through auto-boxing). For this reason, the method signature returns a generic
object, and the client is responsible for casting to the appropriate type if needed for further processing. However,
a cast is performed implicitly on assignment, e.g.:
MyObject o = ... Mapvalue = Dynamic.valueOf(o); ...process value...
Copy Directives
This factory can follow Exclusion and Mapping directives to produce value copies and external value
copies. By default, instance fields marked with the Exclude annotations are excluded from copies. Other
directives can be conveniently produced by the Directives factory> As a simple example:
import static ....Directives.*; MyObject o = ... Mapvalue = Dynamic.valueOf(o,by().excluding(type(MyType.class),annotation(MyAnnotation.class))) .mapping(asString(QName.class));
Cycles and Sharing
Both value copies and external value copies preserve sharing and cycles. Note however that JAXB serialisation of external value copies does not support sharing and will fail in the presence of cycles. Similar restrictions may apply to other serialisation mechanisms, and more generally to other forms of later processing.
| Constructor and Description |
|---|
Dynamic() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
externalValueOf(Object o)
Returns the value copy of an object in a form which is suitable for JAXB serialisation, based on default copy
directives.
|
static <T> T |
externalValueOf(Object o,
Directives directives)
Returns the value copy of an object in a form which is suitable for JAXB serialisation, based on given copy
directives.
|
static <T> T |
valueOf(Object o)
Returns the value copy of an object based on default copy directives.
|
static <T> T |
valueOf(Object o,
Directives directives)
Returns the value copy of an object based on given copy directives.
|
public static <T> T valueOf(Object o) throws Exception
o - the objectException - if the value copy of the object cannot be returnedpublic static <T> T valueOf(Object o, Directives directives) throws Exception
o - the objectdirectives - the copy directivesException - if the value copy of the object cannot be returnedpublic static <T> T externalValueOf(Object o) throws Exception
o - the objectException - if the value copy of the object cannot be returnedpublic static <T> T externalValueOf(Object o, Directives directives) throws Exception
o - the objectdirectives - the copy directivesException - if the value copy of the object cannot be returnedCopyright © 2014. All Rights Reserved.