Search in sources :

Example 1 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project torodb by torodb.

the class ConfigUtils method xmlMapper.

public static XmlMapper xmlMapper() {
    XmlMapper xmlMapper = new XmlMapper();
    configMapper(xmlMapper);
    return xmlMapper;
}
Also used : XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 2 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project bigbluebutton by bigbluebutton.

the class RecordingMetadataReaderHelper method saveRecordingMetadata.

public static void saveRecordingMetadata(File metadataXml, RecordingMetadata recordingMetadata) {
    //XMLOutputFactory factory  = XMLOutputFactory.newInstance();
    JacksonXmlModule module = new JacksonXmlModule();
    module.setDefaultUseWrapper(false);
    XmlMapper mapper = new XmlMapper(module);
    //XMLStreamWriter writer   = null;
    try {
        //writer = factory.createXMLStreamWriter(new FileOutputStream(metadataXml));
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
        mapper.writeValue(metadataXml, recordingMetadata);
    } catch (FileNotFoundException e) {
        log.error("File not found: " + metadataXml.getAbsolutePath(), e);
    } catch (IOException e) {
        log.error("IOException on " + metadataXml.getAbsolutePath(), e);
    }
}
Also used : JacksonXmlModule(com.fasterxml.jackson.dataformat.xml.JacksonXmlModule) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 3 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project bigbluebutton by bigbluebutton.

the class RecordingMetadataReaderHelper method getRecordingMetadata.

public static RecordingMetadata getRecordingMetadata(File metadataXml) {
    XMLInputFactory factory = XMLInputFactory.newInstance();
    JacksonXmlModule module = new JacksonXmlModule();
    // and then configure, for example:
    module.setDefaultUseWrapper(false);
    XmlMapper mapper = new XmlMapper(module);
    //Reading from xml file and creating XMLStreamReader
    XMLStreamReader reader = null;
    RecordingMetadata recMeta = null;
    try {
        reader = factory.createXMLStreamReader(new FileInputStream(metadataXml));
        recMeta = mapper.readValue(reader, RecordingMetadata.class);
    } catch (XMLStreamException e) {
        log.error("Failed to read metadata xml for recording: " + metadataXml.getAbsolutePath(), e);
    } catch (FileNotFoundException e) {
        log.error("File not found: " + metadataXml.getAbsolutePath(), e);
    } catch (IOException e) {
        log.error("IOException on " + metadataXml.getAbsolutePath(), e);
    }
    return recMeta;
}
Also used : JacksonXmlModule(com.fasterxml.jackson.dataformat.xml.JacksonXmlModule) RecordingMetadata(org.bigbluebutton.api.domain.RecordingMetadata) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 4 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project dhis2-core by dhis2.

the class AbstractCrudController method getXmlProperties.

private List<String> getXmlProperties(String payload) throws IOException {
    XmlMapper mapper = DefaultRenderService.getXmlMapper();
    JsonNode root = mapper.readTree(payload);
    return Lists.newArrayList(root.fieldNames());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Example 5 with XmlMapper

use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project jocean-http by isdom.

the class DefaultSignalClient method toRESP.

@SuppressWarnings("unchecked")
private <RESP> RESP toRESP(final FullHttpResponse fullresp, final Class<?> respType, final Class<?> bodyType) {
    if (null != fullresp) {
        try {
            final byte[] bytes = Nettys.dumpByteBufAsBytes(fullresp.content());
            if (LOG.isTraceEnabled()) {
                try {
                    LOG.trace("receive signal response: {}", new String(bytes, CharsetUtil.UTF_8));
                } catch (Exception e) {
                // decode bytes as UTF-8 error, just ignore
                }
            }
            if (null != respType) {
                return DefaultSignalClient.<RESP>convertResponseTo(fullresp, bytes, respType);
            }
            if (null != bodyType) {
                if (bodyType.equals(String.class)) {
                    return (RESP) new String(bytes, CharsetUtil.UTF_8);
                } else {
                    // try need decode as xml
                    final Consumes consumes = bodyType.getAnnotation(Consumes.class);
                    if (null != consumes) {
                        final Collection<String> mimeTypes = Arrays.asList(consumes.value());
                        if (mimeTypes.contains(MediaType.APPLICATION_XML)) {
                            final XmlMapper mapper = new XmlMapper();
                            mapper.addHandler(new DeserializationProblemHandler() {

                                @Override
                                public boolean handleUnknownProperty(final DeserializationContext ctxt, final JsonParser p, final JsonDeserializer<?> deserializer, final Object beanOrClass, final String propertyName) throws IOException {
                                    LOG.warn("UnknownProperty [{}], just skip", propertyName);
                                    p.skipChildren();
                                    return true;
                                }
                            });
                            try {
                                return (RESP) mapper.readValue(bytes, bodyType);
                            } catch (Exception e) {
                                LOG.warn("exception when parse xml, detail: {}", ExceptionUtils.exception2detail(e));
                                return null;
                            }
                        }
                    }
                    // try need decode as json
                    return JSON.<RESP>parseObject(bytes, bodyType);
                }
            } else {
                final RESP respObj = (RESP) bytes;
                return respObj;
            }
        } catch (Exception e) {
            LOG.warn("exception when parse response {}, detail:{}", fullresp, ExceptionUtils.exception2detail(e));
            throw new RuntimeException(e);
        }
    }
    throw new RuntimeException("invalid response");
}
Also used : IOException(java.io.IOException) TransportException(org.jocean.http.TransportException) IOException(java.io.IOException) ErrorDataEncoderException(io.netty.handler.codec.http.multipart.HttpPostRequestEncoder.ErrorDataEncoderException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) DeserializationProblemHandler(com.fasterxml.jackson.databind.deser.DeserializationProblemHandler) Consumes(javax.ws.rs.Consumes) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)62 IOException (java.io.IOException)19 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)15 Test (org.junit.Test)15 InputStream (java.io.InputStream)9 File (java.io.File)8 HttpResponse (org.apache.http.HttpResponse)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 JacksonXmlModule (com.fasterxml.jackson.dataformat.xml.JacksonXmlModule)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Test (org.junit.jupiter.api.Test)5 BadRequestException (ninja.exceptions.BadRequestException)4 EntityReferences (org.apache.cloudstack.backup.veeam.api.EntityReferences)4 Ref (org.apache.cloudstack.backup.veeam.api.Ref)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)2 FileInputStream (java.io.FileInputStream)2