xhtmlContent.updateMacroDefinitions throws error when there is an old macro definition

I have a page that contains a livesearch macro. It was created in an earlier version of Confluence (below 5.8) and still contains the old macro parameter definition for the spaceKey parameter.

If I now try to change any Macro definition on this page by using the xhtmlContent.updateMacroDefinitions it will throw me an error like this:

Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to com.atlassian.confluence.content.render.xhtml.model.resource.identifiers.ResourceIdentifier
at com.atlassian.confluence.content.render.xhtml.storage.macro.StorageMacroV2Marshaller.writeParameterValue(StorageMacroV2Marshaller.java:258)
at com.atlassian.confluence.content.render.xhtml.storage.macro.StorageMacroV2Marshaller.lambda$marshal$0(StorageMacroV2Marshaller.java:116)
at com.atlassian.confluence.content.render.xhtml.transformers.DefaultFragmentTransformer$NonXmlSubstreamable.writeTo(DefaultFragmentTransformer.java:260)
at com.atlassian.confluence.content.render.xhtml.transformers.DefaultFragmentTransformer$AggregatedXmlStreamable.writeTo(DefaultFragmentTransformer.java:278)
at com.atlassian.confluence.content.render.xhtml.storage.StorageXhtmlTransformer.transform(StorageXhtmlTransformer.java:41)

The debugging got me to the point that it seems to be the old macroparameter definition of the livesearch macro.
If I just navigate to the page and save it then there will be an automatic conversion to the new macroparameter definitions of the livesearch macro… but how to achive this programatically?

Or maybe someone can tell me where confluence is doing the magic on migrating old macro parameter definitions during the saveprocess of a page.