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;
}
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);
}
}
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;
}
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());
}
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");
}
Aggregations