1. Convert json string to object
SyncCarriageStatusDTO dto= JSON.parseObject(value,SyncCarriageStatusDTO.class);
2. Convert the enumeration string to the enumeration type
RefTypeEnum refType = RefTypeEnum.valueof (dto.getRefType ())
3. Object is not empty judgment
CollectionUtils.isNotEmpty(carriageRefs)
4. XML string conversion object or XML operation
4.1 Use JAXBContext
JAXBContext jaxbContext = JAXBContext.newInstance(cls);
Unmarshaller um = jaxbContext.createUnmarshaller();
t = (T)um.unmarshal(new StringReader(xmlStr));
4.2 Using 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 Using DocumentHelper.parseText(xml)
Node eventType = document.selectSingleNode("//logisticsEvent/eventHeader/eventType");
if (eventType != null && StringUtils.isNotBlank(eventType.getText())) {
type = CainiaoMessageEventTypeEnum.valueOf(eventType.getText().trim());
}