Example usage for com.fasterxml.jackson.dataformat.xml XmlMapper XmlMapper

List of usage examples for com.fasterxml.jackson.dataformat.xml XmlMapper XmlMapper

Introduction

In this page you can find the example usage for com.fasterxml.jackson.dataformat.xml XmlMapper XmlMapper.

Prototype

public XmlMapper() 

Source Link

Usage

From source file:org.apache.streams.gnip.powertrack.ActivityXMLActivitySerializer.java

public ActivityXMLActivitySerializer() {
    mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE);
    mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE);
    mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE);
    xmlMapper = new XmlMapper();
    xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE);
    xmlMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE);
    xmlMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE);
}

From source file:io.swagger.test.integration.responses.ResponseWithExceptionTestIT.java

@Test
public void verifyApiExceptionAsXml() throws IOException {
    try {//from ww w. j a  va 2s  .  co  m
        final Map<String, String> headerParams = Collections.singletonMap(HttpHeaders.ACCEPT,
                MediaType.APPLICATION_XML);
        client.invokeAPI("/throwApiException", "GET", new HashMap<String, String>(), null, headerParams, null,
                null, null, new String[0]);
        Assert.fail("Exception was expected!");
    } catch (ApiException e) {
        final Response.Status expected = Response.Status.CONFLICT;
        Assert.assertEquals(e.getCode(), expected.getStatusCode());
        final ApiError error = new XmlMapper().readValue(e.getMessage(), ApiError.class);
        Assert.assertEquals(error.getCode(), expected.getStatusCode());
        Assert.assertEquals(error.getMessage(), expected.getReasonPhrase());
    }
}

From source file:org.sakaiproject.serialization.BasicSerializableRepository.java

@Override
public T fromXML(String xml) {
    T obj = null;//ww w  . j ava  2 s . c om
    if (StringUtils.isNotBlank(xml)) {
        XmlMapper mapper = new XmlMapper();
        try {
            obj = mapper.readValue(xml, getDomainClass());
        } catch (IOException e) {
            log.warn("Could not deserialize xml", e);
            obj = null;
        }
    }
    return obj;
}

From source file:com.hp.autonomy.frontend.find.idol.stats.IdolStatsServiceTest.java

@Before
public void setUp() {
    final XmlMapper xmlMapper = new XmlMapper();

    when(configService.getConfig()).thenReturn(config);
    when(config.getStatsServer()).thenReturn(statsServerConfig);
    when(statsServerConfig.isEnabled()).thenReturn(true);

    statsService = new IdolStatsService(aciService, processorFactory, xmlMapper, configService);
}

From source file:com.kurtraschke.wmata.gtfsrealtime.services.WMATAAPIService.java

@PostConstruct
public void start() {
    _jsonMapper = new ObjectMapper();
    _jsonMapper.setPropertyNamingStrategy(PropertyNamingStrategy.PASCAL_CASE_TO_CAMEL_CASE);
    _xmlMapper = new XmlMapper();
    _connectionManager = new BasicHttpClientConnectionManager();
    _limiter = RateLimiter.create(_apiRateLimit);

    if (_apiRateLimit > 9) {
        _log.warn("API rate limit set to {}, greater than default rate limit of 9 queries/second");
    }// ww  w.  j av  a 2 s. c  om
}

From source file:org.glukit.dexcom.sync.responses.ManufacturingDataDatabasePagesResponse.java

public List<ManufacturingParameters> getManufacturingParameters() {
    List<ManufacturingParameters> manufacturingParameters = newArrayList();
    try {// w  ww. j  av a2 s .  c o  m
        for (DatabasePage page : getPages()) {
            ByteArrayInputStream inputStream = new ByteArrayInputStream(page.getPageData());
            DataInput input = this.dataInputFactory.create(inputStream);
            // TODO: something better than ignoring the data?
            long systemSeconds = UnsignedInts.toLong(input.readInt());
            long displaySeconds = UnsignedInts.toLong(input.readInt());

            byte[] xmlBytes = new byte[inputStream.available() - 2];
            input.readFully(xmlBytes);

            validateCrc(input.readUnsignedShort(), page.getPageData());

            XmlMapper xmlMapper = new XmlMapper();
            ManufacturingParameters parameterPage = xmlMapper.readValue(new String(xmlBytes, "UTF-8"),
                    ManufacturingParameters.class);
            manufacturingParameters.add(parameterPage);
        }
        return manufacturingParameters;
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.lightjason.agentspeak.action.builtin.rest.IBaseRest.java

/**
 * reads a xml structure from an url//from   w ww . j a  v a  2s.  c  o  m
 *
 * @param p_url url
 * @return map with xml data
 *
 * @throws IOException is thrown on io errors
 */
@Nonnull
@SuppressWarnings("unchecked")
protected static Map<String, ?> xml(@Nonnull final String p_url) throws IOException {
    return new XmlMapper().readValue(IBaseRest.httpdata(p_url), Map.class);
}

From source file:com.danperron.gamesdbclient.impl.GamesDBClientImpl.java

public GamesDBClientImpl(ExecutorService executorService) {
    xmlMapper = new XmlMapper();
    xmlMapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector());
    xmlMapper.registerModule(new JaxbAnnotationModule());
    xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    this.executorService = executorService;
}

From source file:com.springapp.domain.http.account.Account.java

public String toXML() {
    ObjectMapper xmlMapper = new XmlMapper();
    try {//from  w ww . j av a  2s . c om
        String xml = xmlMapper.writeValueAsString(this);
        return xml;
    } catch (JsonProcessingException e) {
        log.error("Error in creating xml from Account object:{}", this);
    }
    return "";
}

From source file:gt.dakaik.config.WebContext.java

public MappingJackson2HttpMessageConverter jacksonXmlMessageConverter() {
    MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();

    ObjectMapper mapper = new XmlMapper();

    //Registering Hibernate4Module to support lazy objects
    Hibernate4Module module = new Hibernate4Module();
    module.disable(Hibernate4Module.Feature.USE_TRANSIENT_ANNOTATION);
    mapper.registerModule(module);//from w w  w .  j a  va2  s  . c  o  m

    // Cambiar AnnotationIntrospector para usar anotaciones de JAXB
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(mapper.getTypeFactory());
    mapper.setAnnotationIntrospector(introspector);

    List<MediaType> MediaTypes = new ArrayList<>();
    MediaTypes.add(MediaType.APPLICATION_XML);
    messageConverter.setSupportedMediaTypes(MediaTypes);

    messageConverter.setObjectMapper(mapper);
    //log.debug("Listado de MediaTypes: [{}]", messageConverter.getSupportedMediaTypes().toString());

    return messageConverter;

}