teleivo
(Ivo Ulrich)
February 26, 2018, 7:01pm
1
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.
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.serialization;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.beans.EventHandler;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
This file has been truncated. show original
Is the javadoc outdated?
wyclif
(Wyclif Luyima)
February 26, 2018, 9:40pm
2
The javadoc says the alias would be patient , not P atient
teleivo
(Ivo Ulrich)
February 26, 2018, 9:50pm
3
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
wyclif
(Wyclif Luyima)
February 26, 2018, 11:19pm
4
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);
teleivo
(Ivo Ulrich)
February 27, 2018, 6:26am
5
thanks @wyclif ,
I will try that and update the javadoc of the SimpleXStreamSerializer
.