Search in sources :

Example 1 with ToXmlGenerator

use of com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator in project eureka by Netflix.

the class InstanceInfoXmlBeanSerializer method serializeFields.

@Override
protected void serializeFields(Object bean, JsonGenerator jgen0, SerializerProvider provider) throws IOException {
    super.serializeFields(bean, jgen0, provider);
    InstanceInfo instanceInfo = (InstanceInfo) bean;
    ToXmlGenerator xgen = (ToXmlGenerator) jgen0;
    xgen.writeFieldName("port");
    xgen.writeStartObject();
    xgen.setNextIsAttribute(true);
    xgen.writeFieldName("enabled");
    xgen.writeBoolean(instanceInfo.isPortEnabled(PortType.UNSECURE));
    xgen.setNextIsAttribute(false);
    xgen.writeFieldName("port");
    xgen.setNextIsUnwrapped(true);
    xgen.writeString(Integer.toString(instanceInfo.getPort()));
    xgen.writeEndObject();
    xgen.writeFieldName("securePort");
    xgen.writeStartObject();
    xgen.setNextIsAttribute(true);
    xgen.writeStringField("enabled", Boolean.toString(instanceInfo.isPortEnabled(PortType.SECURE)));
    xgen.setNextIsAttribute(false);
    xgen.writeFieldName("securePort");
    xgen.setNextIsUnwrapped(true);
    xgen.writeString(Integer.toString(instanceInfo.getSecurePort()));
    xgen.writeEndObject();
}
Also used : ToXmlGenerator(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 2 with ToXmlGenerator

use of com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator 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();
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ToXmlGenerator(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator)

Example 3 with ToXmlGenerator

use of com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator 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();
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ToXmlGenerator(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator)

Aggregations

ToXmlGenerator (com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator)3 XMLStreamException (javax.xml.stream.XMLStreamException)2 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 InstanceInfo (com.netflix.appinfo.InstanceInfo)1