Adopt Cloudstack 4.2 JSON serialisation design.  With CloudStack 4.2 (and possibly 4.1), complex types are serialised as JSON properties.  The key is the full class name, i.e. includes the package name.  The value of the property is the object's content, which is in turn JSON serialised.
Revise Agent to use the full class name as JSON over HTTP endpoints.
Fix tests, which includes making some settings user settings so that they can be varied.