Search in sources :

Example 1 with JacksonXmlModule

use of com.fasterxml.jackson.dataformat.xml.JacksonXmlModule 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 2 with JacksonXmlModule

use of com.fasterxml.jackson.dataformat.xml.JacksonXmlModule 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 3 with JacksonXmlModule

use of com.fasterxml.jackson.dataformat.xml.JacksonXmlModule in project ninja by ninjaframework.

the class ApiControllerTest method testGetAndPostArticleViaXml.

@Test
public void testGetAndPostArticleViaXml() throws Exception {
    // /////////////////////////////////////////////////////////////////////
    // Test initial data:
    // /////////////////////////////////////////////////////////////////////
    String response = ninjaTestBrowser.makeXmlRequest(getServerAddress() + "api/bob@gmail.com/articles.xml");
    System.out.println("response xml: " + response);
    JacksonXmlModule module = new JacksonXmlModule();
    // and then configure, for example:
    module.setDefaultUseWrapper(false);
    XmlMapper xmlMapper = new XmlMapper(module);
    ArticlesDto articlesDto = xmlMapper.readValue(response, ArticlesDto.class);
    assertEquals(3, articlesDto.articles.size());
    // /////////////////////////////////////////////////////////////////////
    // Post new article:
    // /////////////////////////////////////////////////////////////////////
    ArticleDto articleDto = new ArticleDto();
    articleDto.content = "contentcontent";
    articleDto.title = "new title new title";
    response = ninjaTestBrowser.postXml(getServerAddress() + "api/bob@gmail.com/article.xml", articleDto);
    assertTrue(response.contains("Error. Forbidden."));
    doLogin();
    response = ninjaTestBrowser.postXml(getServerAddress() + "api/bob@gmail.com/article.xml", articleDto);
    assertFalse(response.contains("Error. Forbidden."));
    // /////////////////////////////////////////////////////////////////////
    // Fetch articles again => assert we got a new one ...
    // /////////////////////////////////////////////////////////////////////
    response = ninjaTestBrowser.makeXmlRequest(getServerAddress() + "api/bob@gmail.com/articles.xml");
    articlesDto = xmlMapper.readValue(response, ArticlesDto.class);
    // one new result:
    assertEquals(4, articlesDto.articles.size());
}
Also used : JacksonXmlModule(com.fasterxml.jackson.dataformat.xml.JacksonXmlModule) ArticlesDto(models.ArticlesDto) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) ArticleDto(models.ArticleDto) Test(org.junit.Test) NinjaTest(ninja.NinjaTest)

Example 4 with JacksonXmlModule

use of com.fasterxml.jackson.dataformat.xml.JacksonXmlModule in project ninja by ninjaframework.

the class XmlMapperProvider method get.

@Override
public XmlMapper get() {
    JacksonXmlModule module = new JacksonXmlModule();
    // Check out: https://github.com/FasterXML/jackson-dataformat-xml
    // setDefaultUseWrapper produces more similar output to
    // the Json output. You can change that with annotations in your
    // models.
    module.setDefaultUseWrapper(false);
    XmlMapper xmlMapper = new XmlMapper(module);
    xmlMapper.registerModule(new AfterburnerModule());
    return xmlMapper;
}
Also used : AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) JacksonXmlModule(com.fasterxml.jackson.dataformat.xml.JacksonXmlModule) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Aggregations

JacksonXmlModule (com.fasterxml.jackson.dataformat.xml.JacksonXmlModule)4 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)4 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)1 ArticleDto (models.ArticleDto)1 ArticlesDto (models.ArticlesDto)1 NinjaTest (ninja.NinjaTest)1 RecordingMetadata (org.bigbluebutton.api.domain.RecordingMetadata)1 Test (org.junit.Test)1