添加xml 头信息 encoding ,version
This commit is contained in:
+5
-6
@@ -1,7 +1,6 @@
|
|||||||
package com.gzzn.omms.msgexchangeapi.service.exchange;
|
package com.gzzn.omms.msgexchangeapi.service.exchange;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -9,9 +8,9 @@ import com.fasterxml.jackson.core.JsonParseException;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||||
|
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
|
||||||
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
|
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
|
||||||
import com.gzzn.omms.msgexchangeapi.entity.msg.MSG;
|
import com.gzzn.omms.msgexchangeapi.entity.msg.MSG;
|
||||||
import com.gzzn.omms.msgexchangeapi.exception.ExchangeServiceException;
|
import com.gzzn.omms.msgexchangeapi.exception.ExchangeServiceException;
|
||||||
@@ -30,7 +29,7 @@ public class ExchangeServiceImpl implements IExchangeService {
|
|||||||
@Override
|
@Override
|
||||||
public <T> T xmlstrToObject(String xml,Class<T> valueType) throws ExchangeServiceException {
|
public <T> T xmlstrToObject(String xml,Class<T> valueType) throws ExchangeServiceException {
|
||||||
try {
|
try {
|
||||||
ObjectMapper xmlMapper = new XmlMapper();
|
XmlMapper xmlMapper = new XmlMapper();
|
||||||
xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
xmlMapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
|
xmlMapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
|
||||||
return xmlMapper.readValue(xml,valueType);
|
return xmlMapper.readValue(xml,valueType);
|
||||||
@@ -47,9 +46,9 @@ public class ExchangeServiceImpl implements IExchangeService {
|
|||||||
public String objectToXmlstr(Object object) throws ExchangeServiceException {
|
public String objectToXmlstr(Object object) throws ExchangeServiceException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String xml;
|
XmlMapper xmlMapper = new XmlMapper();
|
||||||
ObjectMapper xmlMapper = new XmlMapper();
|
xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
|
||||||
xml = xmlMapper.writeValueAsString(object);
|
String xml = xmlMapper.writeValueAsString(object);
|
||||||
return xml;
|
return xml;
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new ExchangeServiceException(e.getMessage(),e);
|
throw new ExchangeServiceException(e.getMessage(),e);
|
||||||
|
|||||||
Reference in New Issue
Block a user