XML/JSON serialiser

Hello ,
What is the correct way to serialise object as Json in Camunda engine?
I found this post Cannot find serializer for value 'ObjectValue - #3 by anisk

Camunda will always serialize your custom object type and by default it will serialize to XML or JSON (whichever serializer is first on your classpath) when you set a variable as a process variable.

I am doing as below in my code

HashMap<String, Object> map = new HashMap<>(); 
map.put("orderObjectVar", orderObject);
		   	runtimeService.startProcessInstanceByKey("bk", map);

I get the bellow error sometime

org.camunda.bpm.engine.ProcessEngineException: Cannot serialize object in variable ‘orderObjectVar’: SPIN/DOM-XML-01030 Cannot create context

Caused by: spinjar.com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions

Is this error because XML seriable was detected first in class path?

You can set the default serialization to json. Have a look at this thread: Use json for non-serializable results