use of javax.xml.stream.XMLStreamWriter in project dhis2-core by dhis2.
the class JacksonOrganisationUnitChildrenSerializer method serialize.
@Override
public void serialize(OrganisationUnit value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
if (ToXmlGenerator.class.isAssignableFrom(jgen.getClass())) {
ToXmlGenerator xmlGenerator = (ToXmlGenerator) jgen;
try {
XMLStreamWriter staxWriter = xmlGenerator.getStaxWriter();
staxWriter.writeStartElement(DxfNamespaces.DXF_2_0, "child");
staxWriter.writeAttribute("id", value.getUid());
staxWriter.writeAttribute("name", value.getName());
staxWriter.writeAttribute("created", DATE_FORMAT.format(value.getCreated()));
staxWriter.writeAttribute("lastUpdated", DATE_FORMAT.format(value.getLastUpdated()));
if (value.getHref() != null) {
staxWriter.writeAttribute("href", value.getHref());
}
staxWriter.writeAttribute("hasChildren", String.valueOf(value.hasChild()));
staxWriter.writeEndElement();
} catch (XMLStreamException e) {
//TODO fix
e.printStackTrace();
}
} else {
jgen.writeStartObject();
jgen.writeStringField("id", value.getUid());
jgen.writeStringField("name", value.getName());
jgen.writeFieldName("created");
provider.defaultSerializeDateValue(value.getCreated(), jgen);
jgen.writeFieldName("lastUpdated");
provider.defaultSerializeDateValue(value.getLastUpdated(), jgen);
if (value.getHref() != null) {
jgen.writeStringField("href", value.getHref());
}
jgen.writeBooleanField("hasChildren", value.hasChild());
jgen.writeEndObject();
}
}
use of javax.xml.stream.XMLStreamWriter in project dhis2-core by dhis2.
the class JacksonOrganisationUnitGroupSymbolSerializer method serialize.
@Override
public void serialize(OrganisationUnitGroup value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
if (ToXmlGenerator.class.isAssignableFrom(jgen.getClass())) {
ToXmlGenerator xmlGenerator = (ToXmlGenerator) jgen;
try {
XMLStreamWriter staxWriter = xmlGenerator.getStaxWriter();
staxWriter.writeStartElement(DxfNamespaces.DXF_2_0, "organisationUnitGroup");
staxWriter.writeAttribute("id", value.getUid());
staxWriter.writeAttribute("name", value.getName());
staxWriter.writeAttribute("created", DATE_FORMAT.format(value.getCreated()));
staxWriter.writeAttribute("lastUpdated", DATE_FORMAT.format(value.getLastUpdated()));
if (value.getHref() != null) {
staxWriter.writeAttribute("href", value.getHref());
}
staxWriter.writeAttribute("symbol", String.valueOf(value.getSymbol()));
staxWriter.writeEndElement();
} catch (XMLStreamException e) {
//TODO fix
e.printStackTrace();
}
} else {
jgen.writeStartObject();
jgen.writeStringField("id", value.getUid());
jgen.writeStringField("name", value.getName());
jgen.writeFieldName("created");
provider.defaultSerializeDateValue(value.getCreated(), jgen);
jgen.writeFieldName("lastUpdated");
provider.defaultSerializeDateValue(value.getLastUpdated(), jgen);
if (value.getHref() != null) {
jgen.writeStringField("href", value.getHref());
}
jgen.writeStringField("symbol", value.getSymbol());
jgen.writeEndObject();
}
}
Aggregations