本文整理汇总了Java中com.fasterxml.jackson.dataformat.xml.XmlMapper.writeValueAsString方法的典型用法代码示例。如果您正苦于以下问题:Java XmlMapper.writeValueAsString方法的具体用法?Java XmlMapper.writeValueAsString怎么用?Java XmlMapper.writeValueAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.dataformat.xml.XmlMapper
的用法示例。
在下文中一共展示了XmlMapper.writeValueAsString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generatePayNativeReplyXML
import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入方法依赖的package包/类
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;
}
示例2: toXML
import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入方法依赖的package包/类
@JsonIgnore
public String toXML() throws JsonProcessingException
{
XmlMapper xmlMapper = new XmlMapper();
String xml = xmlMapper.writeValueAsString(this);
return xml;
}
示例3: beanToXml
import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入方法依赖的package包/类
public static String beanToXml(Object obj) {
XmlMapper xml = new XmlMapper();
try {
return xml.writeValueAsString(obj);
} catch (JsonProcessingException e) {
Logger.getLogger(JacksonXmlUtil.class.getName()).log(Level.SEVERE, null, e);
return null;
}
}
示例4: main
import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入方法依赖的package包/类
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
List<Test> list = new ArrayList<>();
Test test = new Test();
test.setName("doctor");
Map<String, String> map = new HashMap<>();
map.put("age", "16");
map.put("ke", "vv");
test.setMap(map);
list.add(test);
Test test2 = new Test();
test2.setName("doctor22");
Map<String, String> map2 = new HashMap<>();
map2.put("age2", "162");
map2.put("ke2", "vv2");
test2.setMap(map2);
list.add(test2);
XmlMapper xmlMapper = new XmlMapper();
String xml = xmlMapper.writeValueAsString(list);
System.out.println(xml);
List<Test> ls = xmlMapper.readValue(xml, new TypeReference<List<Test>>() {
});
Test t = ls.get(0);
System.out.println(t);
System.out.println(t.getName());
System.out.println(t.getMap());
}
示例5: toXML
import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入方法依赖的package包/类
@Override
public String toXML(T t) {
String xml = "";
if (t != null) {
sessionFactory.getCurrentSession().refresh(t);
XmlMapper mapper = new XmlMapper();
try {
xml = mapper.writeValueAsString(t);
} catch (JsonProcessingException e) {
log.warn("Could not serialize to xml", e);
xml = "";
}
}
return xml;
}
示例6: Test_ById
import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入方法依赖的package包/类
@Test
public void Test_ById() throws Exception
{
XmlMapper xmlMapper = new XmlMapper();
for (EdiUser u : edi.querByList())
{
String xml = xmlMapper.writeValueAsString(u);
System.out.println(xml);
List<Requestorder> r = u.getRequestorders();
if (r == null)
{
System.out.println(11);
}
else
{
for (Requestorder requestorder : r)
{
Item item = requestorder.getItem();
if (item != null)
{
System.out.println(item.getUid());
}
else
{
System.out.println(111);
}
Receiver receiver = requestorder.getReceiver();
if (receiver != null)
{
System.out.println(receiver.getUid());
}
else
{
System.out.println(111);
}
Sender sender = requestorder.getSender();
if (sender != null)
{
System.out.println(sender.getUid());
}
else
{
System.out.println(1111);
}
}
}
}
}
示例7: convert_json_to_xml_jackson
import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入方法依赖的package包/类
@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);
}
示例8: toXML
import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入方法依赖的package包/类
public String toXML() throws JsonProcessingException
{
XmlMapper xmlMapper = new XmlMapper();
String xml = xmlMapper.writeValueAsString(this);
return xml;
}
示例9: convertToXML
import com.fasterxml.jackson.dataformat.xml.XmlMapper; //导入方法依赖的package包/类
/**
* Convert a JSON string to XML. No direct mapping could be found. So we do a convert
* to map then use the xmlMapper to convert the Map to XML
* @param jsonString
* @return
* @throws JsonParseException
* @throws JsonMappingException
* @throws IOException
*/
public static String convertToXML(String jsonString) throws JsonParseException, JsonMappingException, IOException
{
XmlMapper xmlMapper = new XmlMapper();
return xmlMapper.writeValueAsString(JsonUtil.convertToMap(jsonString));
}