标签:parse 枚举类型 head 利用 win sage ges temp str
1.json 字符串转换成对象
SyncCarriageStatusDTO dto= JSON.parseObject(value,SyncCarriageStatusDTO.class);
2.枚举字符串转换成枚举类型
RefTypeEnum refType=RefTypeEnum.valueof(dto.getRefType())
3.对象不为空判断
CollectionUtils.isNotEmpty(carriageRefs)
4.XML字符串转换对象或进行XML操作
4.1 利用 JAXBContext
JAXBContext jaxbContext = JAXBContext.newInstance(cls);
Unmarshaller um = jaxbContext.createUnmarshaller();
t = (T)um.unmarshal(new StringReader(xmlStr));
4.2 利用 XStream
if(! xmap.containsKey(cls.getName())){
XStream xstream = new XStream(new DomDriver());
xstream.processAnnotations(cls);
xstream.ignoreUnknownElements();
xmap.put(cls.getName(), xstream);
}
T t = (T) xmap.get(cls.getName()).fromXML(xmlStr);
4.3利用 DocumentHelper.parseText(xml)
Node eventType = document.selectSingleNode("//logisticsEvent/eventHeader/eventType");
if (eventType != null && StringUtils.isNotBlank(eventType.getText())) {
type = CainiaoMessageEventTypeEnum.valueOf(eventType.getText().trim());
}
标签:parse 枚举类型 head 利用 win sage ges temp str
原文地址:https://www.cnblogs.com/chengjun/p/8969052.html