List of usage examples for com.fasterxml.jackson.dataformat.xml XmlMapper XmlMapper
public XmlMapper()
From source file:com.orange.ngsi.model.ContextAttributeModelTest.java
@Test public void serializationXMLContextAttribute() throws IOException, XPathExpressionException { ContextAttribute contextAttribute = new ContextAttribute("A", "T", "22"); ObjectMapper xmlmapper = new XmlMapper(); String xml = xmlmapper.writeValueAsString(contextAttribute); assertTrue(xml.contains("A")); assertTrue(xml.contains("T")); assertTrue(xml.contains("22")); String xpathExpr = "/ContextAttribute/name"; XPath xPath = XPathFactory.newInstance().newXPath(); assertEquals("A", xPath.evaluate(xpathExpr, new InputSource(new StringReader(xml)))); }
From source file:org.apache.streams.gnip.powertrack.GnipActivityFixer.java
public GnipActivityFixer() { 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:com.gnip.test.YouTubeEDCSerDeTest.java
@Test public void Tests() throws Exception { 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); InputStream is = YouTubeEDCSerDeTest.class.getResourceAsStream("/YoutubeEDC.xml"); if (is == null) System.out.println("null"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); XmlMapper 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); ObjectMapper jsonMapper = new ObjectMapper(); try {/*from w w w . j ava 2s. co m*/ while (br.ready()) { String line = br.readLine(); //LOGGER.debug(line); Object activityObject = xmlMapper.readValue(line, Object.class); String jsonObject = jsonMapper.writeValueAsString(activityObject); //LOGGER.debug(jsonObject); } } catch (Exception e) { e.printStackTrace(); Assert.fail(); } }
From source file:org.apache.streams.gnip.flickr.test.FlickrEDCSerDeTest.java
@Test public void Tests() throws Exception { 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); InputStream is = FlickrEDCSerDeTest.class.getResourceAsStream("/FlickrEDC.xml"); if (is == null) System.out.println("null"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); XmlMapper 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); xmlMapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, Boolean.FALSE); ObjectMapper jsonMapper = new ObjectMapper(); try {//from w w w .jav a 2s . com while (br.ready()) { String line = br.readLine(); //LOGGER.debug(line); Object activityObject = xmlMapper.readValue(line, Object.class); String jsonObject = jsonMapper.writeValueAsString(activityObject); //LOGGER.debug(jsonObject); } } catch (Exception e) { e.printStackTrace(); Assert.fail(); } }
From source file:org.sakaiproject.serialization.BasicSerializableRepository.java
@Override public String toXML(T t) { String xml = ""; if (t != null) { sessionFactory.getCurrentSession().refresh(t); XmlMapper mapper = new XmlMapper(); try {/*from ww w. ja v a 2s. c o m*/ xml = mapper.writeValueAsString(t); } catch (JsonProcessingException e) { log.warn("Could not serialize to xml", e); xml = ""; } } return xml; }
From source file:info.donsun.cache.filecache.FileCacheManager.java
/** * Parse cache config file/* ww w . j a va 2s . com*/ * * @param resourceAsStream * @return */ private static void parseConfigFile(InputStream resourceAsStream) { try { XmlMapper mapper = new XmlMapper(); fileCacheConfig = mapper.reader(FileCacheConfig.class).readValue(resourceAsStream); String defaultDir = fileCacheConfig.getDefaultDir(); Long defaultExpireTime = fileCacheConfig.getDefaultExpireTime(); List<CacheConfig> cacheConfigs = fileCacheConfig.getCaches(); if (cacheConfigs != null && cacheConfigs.size() > 0) { for (CacheConfig cache : cacheConfigs) { Assert.notNull(cache.getName(), "Cache name must not be null."); if (StringUtils.isBlank(cache.getDir())) { cache.setDir(defaultDir); } if (cache.getExpireTime() == null) { cache.setExpireTime(defaultExpireTime); } caches.put(cache.getName(), cache); } } } catch (JsonProcessingException e) { LOG.error("Parse cache config file exception.", e); } catch (IOException e) { LOG.error("Reade cache config file exception.", e); } catch (IllegalArgumentException e) { LOG.error("Illegal argument of cache name." + e.getMessage(), e); } }
From source file:io.apiman.test.integration.rest.plugins.policies.transformplugin.AbstractTransformationIT.java
protected TestData xmlToTestDataObject(String xml) throws IOException { return new XmlMapper().readValue(xml, TestData.class); }
From source file:com.gnip.test.YoutubeEDCAsActivityTest.java
@Test @Ignore/*w ww .j av a 2 s . co m*/ public void Tests() throws Exception { 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); InputStream is = YoutubeEDCAsActivityTest.class.getResourceAsStream("/YoutubeEDC.xml"); if (is == null) System.out.println("null"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); XmlMapper 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); ObjectMapper jsonMapper = new ObjectMapper(); try { while (br.ready()) { String line = br.readLine(); //LOGGER.debug(line); Object activityObject = xmlMapper.readValue(line, Object.class); String jsonString = jsonMapper.writeValueAsString(activityObject); JSONObject jsonObject = new JSONObject(jsonString); JSONObject fixedObject = GnipActivityFixer.fix(jsonObject); Activity activity = jsonMapper.readValue(fixedObject.toString(), Activity.class); //LOGGER.debug(des); } } catch (Exception e) { e.printStackTrace(); Assert.fail(); } }
From source file:org.apache.streams.gnip.flickr.test.FlickrEDCAsActivityTest.java
@Ignore @Test/*from w ww.ja va 2s . c o m*/ public void Tests() throws Exception { 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); InputStream is = FlickrEDCAsActivityTest.class.getResourceAsStream("/FlickrEDC.xml"); if (is == null) System.out.println("null"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); XmlMapper 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); ObjectMapper jsonMapper = new ObjectMapper(); try { while (br.ready()) { String line = br.readLine(); //LOGGER.debug(line); Object activityObject = xmlMapper.readValue(line, Object.class); String jsonString = jsonMapper.writeValueAsString(activityObject); JSONObject jsonObject = new JSONObject(jsonString); JSONObject fixedObject = GnipActivityFixer.fix(jsonObject); Activity activity = null; try { activity = jsonMapper.readValue(fixedObject.toString(), Activity.class); } catch (Exception e) { LOGGER.error(jsonObject.toString()); LOGGER.error(fixedObject.toString()); e.printStackTrace(); Assert.fail(); } //LOGGER.debug(des); } } catch (Exception e) { e.printStackTrace(); Assert.fail(); } }
From source file:org.lightjason.agentspeak.action.buildin.rest.IBaseRest.java
/** * reads a xml structure from an url// w ww.ja va 2s . c o m * * @param p_url url * @return map with xml data * @throws IOException is thrown on io errors */ @SuppressWarnings("unchecked") protected static Map<String, ?> xml(final String p_url) throws IOException { return new XmlMapper().readValue(IBaseRest.httpdata(p_url), Map.class); }