SimpleXStreamSerializer says it aliases but does not


the org.openmrs.serialization.SimpleXStreamSerializer javadoc says that

All classes are automatically aliased. So a serialization of the Patient class will not be <org.openmrs.Patient> but instead will be <Patient>

but it does not. There is even a test that it does not.

Is the javadoc outdated?

The javadoc says the alias would be patient, not Patient

you are right on that. was a typo on my part.

but what I am aiming at is

		OpenmrsSerializer serializer = new SimpleXStreamSerializer();
		Patient p = new Patient();
		String serialized = serializer.serialize(p);

leads to


yet I thought it should be aliased to patient not org.openmrs.Patient

I think that simple serializer doesn’t have the aliases configured, you can use the one from the serialization module, the recommended practice is to get your preferred serializer from the service like below:

String xml = Context.getSerializationService().serialize(patient, XStreamSerializer.class);

The above would only compile if you have the serialization module jar on the classpath.

Alternatively, assuming the serialization module will exist at runtime, you can set the fully qualified class name of the serializer from the serialization module as the value of the GP named serialization.defaultSerializer and then your code would change to

String xml = Context.getSerializationService().getDefaultSerializer().serialize(patient);

thanks @wyclif, I will try that and update the javadoc of the SimpleXStreamSerializer.