mapEqualNames() Macro
Syntax |
| |
---|---|---|
Semantics | The macro generates set statements for all equal named, equally typed attributes found in the target object and at least one of the input objects. This applies to all public attributes including all inherited attributes. You can supply multiple input objects. This macro does not work recursively and thus do not perform a deep copy of attributes of complex types. | |
Substitutables |
| Can be any complex object having attributes of any type. |
Examples |
NONE
|
Usage of mapEqualNames()
Given are the two unrelated classes Person and DetailedPerson.
Data / Script | Description / Result |
---|---|
JSON
| The object personIn is of type DetailedPerson. |
NONE
| This statement assigns values to the matching attributes of object personOut which is of type Person :
JSON
age and country remain unset. |
Usage of "mapEqualNamesIfExists()"
Data / Script | Description / Result |
---|---|
JSON
| The object personIn1of type Person already contains values. |
JSON
| The object personIn2 is of type DetailedPerson. |
NONE
| This statement assigns values from personIn2 to the matching attributes of personIn1:
JSON
The properties of personIn1 get overwritten with existing values. The value of street remains unchanged, because it did not exist in the source object personIn2 (was NULL). |
Usage of mapEqualNames() with the "append" Statement
You can use mapEqualNames()
along with the append Statement to add a complex object with numerous attributes to an array of unrelated objects which needs only some of the information. The mapEqualNames()
macro will create set statements for all equal named attributes found in the target object while the append
statement will add the result to an array.
Given are the two unrelated classes Person and DetailedPerson.
Data / Script | Description / Result |
---|---|
JSON
| Assume that aDetailedPerson is provided from an external source. For further processing, we are interested in name and surname only. |
CODE
|
Result array:
JSON
|
Related Pages: