提交xml转object 代码 ,使用jaxb 注解。同时忽略未知字段
This commit is contained in:
@@ -92,12 +92,7 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>xerces</groupId>
|
||||
<artifactId>xercesImpl</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -18,6 +18,8 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlSchemaType;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
|
||||
/**
|
||||
* <p>anonymous complex type的 Java 类。
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.gzzn.omms.msgexchangeapi.runner;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -39,10 +40,6 @@ public class AppRunner implements CommandLineRunner {
|
||||
|
||||
logger.info("发送获取动态航班日计划的消息完成");
|
||||
|
||||
|
||||
//启动线程等待日航班计划消息返回
|
||||
Thread t = new Thread(new SchdWaitRunner());
|
||||
t.run();
|
||||
|
||||
Executors.newFixedThreadPool(1).execute(new SchdWaitRunner());
|
||||
}//end function run
|
||||
}
|
||||
|
||||
@@ -7,9 +7,12 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
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.module.jaxb.JaxbAnnotationIntrospector;
|
||||
import com.gzzn.omms.msgexchangeapi.exception.ExchangeServiceException;
|
||||
|
||||
@Service("exchangeService")
|
||||
@@ -35,6 +38,8 @@ public class ExchangeServiceImpl implements IExchangeService {
|
||||
public <T> T xmlstrToObject(String xml,Class<T> valueType) throws ExchangeServiceException {
|
||||
try {
|
||||
ObjectMapper xmlMapper = new XmlMapper();
|
||||
xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
xmlMapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
|
||||
return xmlMapper.readValue(xml,valueType);
|
||||
} catch (JsonParseException e) {
|
||||
throw new ExchangeServiceException(e.getMessage(),e);
|
||||
|
||||
Reference in New Issue
Block a user