Java Code Examples for com.fasterxml.jackson.dataformat.xml.XmlMapper#writeValueAsString()
The following examples show how to use
com.fasterxml.jackson.dataformat.xml.XmlMapper#writeValueAsString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PayUtils.java From weixin-pay with MIT License | 6 votes |
public static String generatePayNativeReplyXML(PayPackage payPackage){ try { Map<String, String> map = BeanUtils.describe(payPackage); map.remove("class"); String sign = Signature.generateSign(map); payPackage.setSign(sign); XmlMapper xmlMapper = new XmlMapper(); xmlMapper.setSerializationInclusion(Include.NON_EMPTY); String xmlContent = xmlMapper.writeValueAsString(payPackage); HttpsRequest httpsRequest = new HttpsRequest(); String result = httpsRequest.sendPost(Configure.UNIFY_PAY_API, xmlContent); return result; } catch (Exception e) { logger.info("e:" + e); } return null; }
Example 2
Source File: MockUser.java From jfilter with Apache License 2.0 | 5 votes |
public String toXmlString() { XmlMapper mapper = Jackson2ObjectMapperBuilder.xml().build(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); try { return mapper.writeValueAsString(this); } catch (JsonProcessingException e) { return super.toString(); } }
Example 3
Source File: WxUtils.java From seezoon-framework-all with Apache License 2.0 | 5 votes |
public static String beanToXml(Object bean) { Assert.notNull(bean,"bean 为null"); XmlMapper xmlMapper = new XmlMapper(); xmlMapper.setSerializationInclusion(Include.NON_NULL); try { return xmlMapper.writeValueAsString(bean); } catch (JsonProcessingException e) { throw new ServiceException(e.getMessage()); } }
Example 4
Source File: T.java From seezoon-framework-all with Apache License 2.0 | 5 votes |
@Test public void t9() throws JsonProcessingException { UnifiedOrder order = new UnifiedOrder(); order.setAppid("1"); XmlMapper xmlMapper = new XmlMapper(); xmlMapper.setSerializationInclusion(Include.NON_NULL); String writeValueAsString = xmlMapper.writeValueAsString(order); System.out.println(writeValueAsString); UnifiedOrder xmlToBean = WxUtils.xmlToBean(writeValueAsString, UnifiedOrder.class); System.out.println(JSON.toJSONString(xmlToBean)); }
Example 5
Source File: EmailAttachmentFileCreator.java From blackduck-alert with Apache License 2.0 | 5 votes |
private File createXmlFile(MessageContentGroup messageContentGroup, File writeDir) throws IOException { XmlMapper xmlMapper = new XmlMapper(); xmlMapper.registerModule(new Jdk8Module()); String xmlMessage = xmlMapper.writeValueAsString(messageContentGroup); return createFile(xmlMessage, writeDir, "xml"); }
Example 6
Source File: BasicSerializableRepository.java From sakai with Educational Community License v2.0 | 5 votes |
@Override public String toXML(T t) { String xml = ""; if (t != null) { sessionFactory.getCurrentSession().refresh(t); final XmlMapper mapper = createXMLMapper(); try { xml = mapper.writeValueAsString(t); } catch (JsonProcessingException e) { log.warn("Could not serialize to xml", e); xml = ""; } } return xml; }
Example 7
Source File: BasicSerializableRepository.java From sakai with Educational Community License v2.0 | 5 votes |
@Override public String toXML(T t) { String xml = ""; if (t != null) { sessionFactory.getCurrentSession().refresh(t); final XmlMapper mapper = createXMLMapper(); try { xml = mapper.writeValueAsString(t); } catch (JsonProcessingException e) { log.warn("Could not serialize to xml", e); xml = ""; } } return xml; }
Example 8
Source File: XMLSerializeDeserializeUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void whenJavaSerializedToXmlStr_thenCorrect() throws JsonProcessingException { XmlMapper xmlMapper = new XmlMapper(); String xml = xmlMapper.writeValueAsString(new SimpleBean()); assertNotNull(xml); }
Example 9
Source File: ConvertJSONtoXML.java From levelup-java-examples with Apache License 2.0 | 4 votes |
@Test public void convert_json_to_xml_jackson () throws IOException { String browsersAsJson ="[{\"name\":\"Chrome\"},{\"name\":\"FireFox\"},{\"name\":\"Internet Explorer\"}]\n"; ObjectMapper jsonMapper = new ObjectMapper(); @SuppressWarnings("unchecked") List<Browser> browsers = jsonMapper.readValue(browsersAsJson, List.class); XmlMapper xmlMapper = new XmlMapper(); String browsersAsXml = xmlMapper.writeValueAsString(browsers); logger.info(browsersAsXml); assertTrue(browsersAsXml.length() > 0); }