完善修正xml转json消息的问题。
This commit is contained in:
+5
-12
@@ -13,25 +13,18 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.MSG;
|
||||
import com.gzzn.omms.msgexchangeapi.exception.ExchangeServiceException;
|
||||
import com.gzzn.omms.msgexchangeapi.utils.JsonUtil;
|
||||
|
||||
@Service("exchangeService")
|
||||
public class ExchangeServiceImpl implements IExchangeService {
|
||||
|
||||
@Override
|
||||
public String xmlstrToJson(String xml) throws ExchangeServiceException {
|
||||
try {
|
||||
Map map;
|
||||
ObjectMapper xmlMapper = new XmlMapper();
|
||||
map = xmlMapper.readValue(xml, Map.class);
|
||||
map.remove("noNamespaceSchemaLocation");
|
||||
|
||||
ObjectMapper jsonMapper = new ObjectMapper();
|
||||
String json = jsonMapper.writer().withDefaultPrettyPrinter().writeValueAsString(map);
|
||||
return json;
|
||||
} catch (IOException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
}
|
||||
MSG msg = xmlstrToObject(xml,MSG.class); //转具体消息
|
||||
String jsonStr = JsonUtil.getStringWithNoneKey(msg); //转json同时去除null的key
|
||||
return jsonStr;
|
||||
} //end function
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user