重新更加xsd生成所有的消息pojo类 。并完整重构代码

This commit is contained in:
zhouxiunai
2018-12-07 15:29:28 +08:00
parent c02dc7929b
commit 63ffe59fd4
176 changed files with 32695 additions and 1757 deletions
@@ -0,0 +1,60 @@
package com.gzzn.omms.msgexchangeapi.service.exchange;
import java.io.IOException;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.gzzn.omms.msgexchangeapi.exception.ExchangeServiceException;
@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);
}
} //end function
@Override
public <T> T xmlstrToObject(String xml,Class<T> valueType) throws ExchangeServiceException {
try {
ObjectMapper xmlMapper = new XmlMapper();
return xmlMapper.readValue(xml,valueType);
} catch (JsonParseException e) {
throw new ExchangeServiceException(e.getMessage(),e);
} catch (JsonMappingException e) {
throw new ExchangeServiceException(e.getMessage(),e);
} catch (IOException e) {
throw new ExchangeServiceException(e.getMessage(),e);
}
} //end function
@Override
public String objectToXmlstr(Object object) throws ExchangeServiceException {
try {
String xml;
ObjectMapper xmlMapper = new XmlMapper();
xml = xmlMapper.writeValueAsString(object);
return xml;
} catch (JsonProcessingException e) {
throw new ExchangeServiceException(e.getMessage(),e);
}
}
}
@@ -0,0 +1,14 @@
package com.gzzn.omms.msgexchangeapi.service.exchange;
import com.gzzn.omms.msgexchangeapi.exception.ExchangeServiceException;
/**
* 消息转换服务
* @author Administrator
*
*/
public interface IExchangeService {
public String xmlstrToJson(String xml) throws ExchangeServiceException;
public <T> T xmlstrToObject(String xml,Class<T> valueType) throws ExchangeServiceException;
public String objectToXmlstr(Object object) throws ExchangeServiceException;
}