SimpleXStreamSerializer says it aliases but does not

Hi,

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();
		p.setPersonId(1);
		p.setUuid("123");
		p.setVoided(false);
		
		String serialized = serializer.serialize(p);
		System.out.println(serialized);

leads to

<org.openmrs.Patient>
  <uuid>123</uuid>
  <voided>false</voided>
  <personId>1</personId>
  <birthdateEstimated>false</birthdateEstimated>
  <deathdateEstimated>false</deathdateEstimated>
  <dead>false</dead>
  <personVoided>false</personVoided>
  <isPatient>true</isPatient>
  <patientId>1</patientId>
  <allergyStatus>Unknown</allergyStatus>
</org.openmrs.Patient>

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.