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