Recording complex objects
How to record complex objects in JAVA
To use this feature, create a rdbDisplay file in the project root directory. It will store information about which methods to use to serialize objects. You can provide a customized method that serializes only relevant business logic data.
Each line in the file should contain information about a single type and the corresponding serialization method. The type name must include a full namespace and after a colon, it defines an object method or a fully qualified static method that accepts one parameter of the corresponding type, which RevDeBug will use to serialize the object content.
In the above example, the toString method of the JSONObject object was used to serialize the content of JSONObject objects transmitted in the source code.
In our demo application, the CalculateReconcilation(String id) method analyzes data from the JSON file. When using RevDeBug recording, the content of the analyzed file is preserved and visible while browsing the recording even if the file or the whole process no longer exists.
Below is the result of such action shown in the RevDeBug interface:
For 3rd party classes, where there is no suitable toString implementation you can povide an external serialization method by defining in a helper class a static public method receiving one parameter of this 3rd party object's type and returning a String representation. Assuming you would implement this method like in the example below:
you can then reference this helper method in the rdbDisplay file using the fully qualified name of the method and class it was implemented in like this:
Automatic Recording Complex Objects
You can automate this process by adding these parameters for compiler to the build file :
Name | Explanation |
---|---|
-AREVDEBUG_RDBDISPLAY_AUTOGEN | Usage: Instructs RevDeBug Compiler to automatically generate RDBDisplay rules for every class in the compiled project (i.e. which compiler compiles) that overrides toString() method. This requires a performance consideration as RevDeBug will use implemented toString() methods to serialize the state of the object during runtime. Defaults to 'false' (do not generate RDBDisplay rules automatically). |
-AREVDEBUG_RDBDISPLAY_AUTOGEN_ARRAYS=true | Usage: Instructs RevDeBug Compiler to automatically generate RDBDisplay rules for displaying first elements of arrays of basic types (Integers, String, etc). This requires a performance consideration as RevDeBug will serialize the state of those arrays during runtime. Defaults to 'false' (do not generate RDBDisplay rules automatically). |
-AREVDEBUG_RDBDISPLAY_AUTOGEN_COLLECTIONS=true | Usage: Instructs RevDeBug Compiler to automatically generate RDBDisplay rules for displaying first elements of collections of basic types (Integers, String, etc). This requires a performance consideration as RevDeBug will serialize the state of those/ collections during runtime. Defaults to 'false' (do not generate RDBDisplay rules automatically). |
Last updated