Never tried it but according to the Javadocs, ModelNode has a clone() method, does it do anything clever?
Clone apparently does an exact copy of a node, but trying to add it fails with the same error.
It it possible that a part of the configuration read via the management API cannot be used for adding it under another name? Should it be processed somehow? Please advice.
Is anyone aware of some other method for achieving this?
You have to :add() the children of the server group (like jvm) separately. The server-group:add() only takes a reference to the jvm, not the whole submodel.
The :read-resource-description and :read-operation-description should give you more details on what attributes the operation requires.
Is there a general method for transforming the read ModelNode instance into a ModelNode which can be used for writing, without "knowing" its specific structure.
This could be used to make an exact copy of some configuration part. I think this could be useful in other cases as well (e.g. duplicate a datasource, and change only some relevant information, etc.)
The closes to what you are looking for is :describe() operation on subsystem for instance /subsystem=mail:describe
but what you want makes a reasonable new feature we should have.
can you create jira for it