use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project ninja by ninjaframework.
the class BodyParserEngineXmlTest method testEmptyXmlBody.
@Test
public void testEmptyXmlBody() {
final String xmlDocument = "";
final InputStream is = new ByteArrayInputStream(xmlDocument.getBytes());
final XmlMapper xmlObjMapper = new XmlMapper();
final BodyParserEngineXml bodyParserEngineXml = new BodyParserEngineXml(xmlObjMapper);
boolean badRequestThrown = false;
try {
Mockito.when(context.getInputStream()).thenReturn(is);
} catch (IOException ignore) {
}
try {
bodyParserEngineXml.invoke(context, SimpleTestForm.class);
} catch (BadRequestException ignore) {
badRequestThrown = true;
} finally {
try {
is.close();
} catch (IOException ignore) {
}
}
assertTrue(badRequestThrown);
}
use of com.fasterxml.jackson.dataformat.xml.XmlMapper in project ninja by ninjaframework.
the class BodyParserEngineXmlTest method testValidXmlBody.
@Test
public void testValidXmlBody() {
final String xmlDocument = String.format("<form><firstName>%s</firstName><lastName>%s</lastName><birthYear>%d</birthYear><lastSeen>%s</lastSeen></form>", BodyParserEngineXmlTest.DATA_FIRSTNAME, BodyParserEngineXmlTest.DATA_LASTNAME, BodyParserEngineXmlTest.DATA_BIRTHYEAR, BodyParserEngineXmlTest.DATA_LASTSEEN);
final InputStream is = new ByteArrayInputStream(xmlDocument.getBytes());
final XmlMapper xmlObjMapper = new XmlMapper();
final BodyParserEngineXml bodyParserEngineXml = new BodyParserEngineXml(xmlObjMapper);
SimpleTestForm testForm = null;
try {
Mockito.when(context.getInputStream()).thenReturn(is);
} catch (IOException ignore) {
}
try {
testForm = bodyParserEngineXml.invoke(context, SimpleTestForm.class);
} catch (BadRequestException ignore) {
} finally {
try {
is.close();
} catch (IOException ignore) {
}
}
final Calendar cal = Calendar.getInstance();
final SimpleDateFormat dateFormat = new SimpleDateFormat(BodyParserEngineXmlTest.PARSER_DATEFORMAT);
dateFormat.setTimeZone(TimeZone.getTimeZone(BodyParserEngineXmlTest.PARSER_DATETZ));
try {
cal.setTime(dateFormat.parse(BodyParserEngineXmlTest.DATA_LASTSEEN));
} catch (ParseException ignore) {
}
cal.setTimeZone(TimeZone.getTimeZone(BodyParserEngineXmlTest.PARSER_DATETZ));
assertTrue(testForm != null);
assertThat(testForm.firstName, equalTo(BodyParserEngineXmlTest.DATA_FIRSTNAME));
assertThat(testForm.lastName, equalTo(BodyParserEngineXmlTest.DATA_LASTNAME));
assertThat(testForm.birthYear, CoreMatchers.equalTo(BodyParserEngineXmlTest.DATA_BIRTHYEAR));
assertTrue(testForm.lastSeen != null);
assertTrue(testForm.lastSeen.compareTo(cal) == 0);
}
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 spring-framework by spring-projects.
the class MappingJackson2XmlViewTests method renderWithCustomSerializerLocatedByFactory.
@Test
public void renderWithCustomSerializerLocatedByFactory() throws Exception {
SerializerFactory factory = new DelegatingSerializerFactory(null);
XmlMapper mapper = new XmlMapper();
mapper.setSerializerFactory(factory);
view.setObjectMapper(mapper);
Object bean = new TestBeanSimple();
Map<String, Object> model = new HashMap<>();
model.put("foo", bean);
view.render(model, request, response);
String result = response.getContentAsString();
assertTrue(result.length() > 0);
assertTrue(result.contains("custom</testBeanSimple>"));
validateResult();
}
Aggregations