处理BDPB标签体只包含空白换行符导致转换对象报错问题。
添加单元测试程序
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
package com.gzzn.omms.msgexchangeapi.dao;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
import com.gzzn.omms.msgexchangeapi.entity.CminmsgTest;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public interface CminmsgTestDao extends CrudRepository<CminmsgTest, Long> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
package com.gzzn.omms.msgexchangeapi.entity;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The persistent class for the CMINMSGS database table.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name="CMINMSGS_TEST")
|
||||||
|
public class CminmsgTest implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
|
@Column(name="CMINMSGS_ID")
|
||||||
|
private long cminmsgsId;
|
||||||
|
|
||||||
|
@Lob
|
||||||
|
@Column(name="CMINMSGS_CLOB_MSG")
|
||||||
|
private String cminmsgsClobMsg;
|
||||||
|
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
@Column(name="CMINMSGS_DATE_PROCESSED")
|
||||||
|
private Date cminmsgsDateProcessed;
|
||||||
|
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
@Column(name="CMINMSGS_DATE_RECEIVED")
|
||||||
|
private Date cminmsgsDateReceived;
|
||||||
|
|
||||||
|
@Column(name="CMINMSGS_STATUS")
|
||||||
|
private String cminmsgsStatus;
|
||||||
|
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
@Column(name="CMINMSGS_SUBSYSTEM_DATE_SENT")
|
||||||
|
private Date cminmsgsSubsystemDateSent;
|
||||||
|
|
||||||
|
@Column(name="CMINMSGS_SUBSYSTEM_NAME")
|
||||||
|
private String cminmsgsSubsystemName;
|
||||||
|
|
||||||
|
@Column(name="CMINMSGS_SUBSYSTEM_SEQUENCE")
|
||||||
|
private String cminmsgsSubsystemSequence;
|
||||||
|
|
||||||
|
@Column(name="CMINMSGS_SUBSYSTEM_SUBTYPE")
|
||||||
|
private String cminmsgsSubsystemSubtype;
|
||||||
|
|
||||||
|
@Column(name="CMINMSGS_SUBSYSTEM_TYPE")
|
||||||
|
private String cminmsgsSubsystemType;
|
||||||
|
|
||||||
|
public CminmsgTest() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCminmsgsId() {
|
||||||
|
return this.cminmsgsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCminmsgsId(long cminmsgsId) {
|
||||||
|
this.cminmsgsId = cminmsgsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCminmsgsClobMsg() {
|
||||||
|
return this.cminmsgsClobMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCminmsgsClobMsg(String cminmsgsClobMsg) {
|
||||||
|
this.cminmsgsClobMsg = cminmsgsClobMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCminmsgsDateProcessed() {
|
||||||
|
return this.cminmsgsDateProcessed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCminmsgsDateProcessed(Date cminmsgsDateProcessed) {
|
||||||
|
this.cminmsgsDateProcessed = cminmsgsDateProcessed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCminmsgsDateReceived() {
|
||||||
|
return this.cminmsgsDateReceived;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCminmsgsDateReceived(Date cminmsgsDateReceived) {
|
||||||
|
this.cminmsgsDateReceived = cminmsgsDateReceived;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCminmsgsStatus() {
|
||||||
|
return this.cminmsgsStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCminmsgsStatus(String cminmsgsStatus) {
|
||||||
|
this.cminmsgsStatus = cminmsgsStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCminmsgsSubsystemDateSent() {
|
||||||
|
return this.cminmsgsSubsystemDateSent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCminmsgsSubsystemDateSent(Date cminmsgsSubsystemDateSent) {
|
||||||
|
this.cminmsgsSubsystemDateSent = cminmsgsSubsystemDateSent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCminmsgsSubsystemName() {
|
||||||
|
return this.cminmsgsSubsystemName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCminmsgsSubsystemName(String cminmsgsSubsystemName) {
|
||||||
|
this.cminmsgsSubsystemName = cminmsgsSubsystemName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCminmsgsSubsystemSequence() {
|
||||||
|
return this.cminmsgsSubsystemSequence;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCminmsgsSubsystemSequence(String cminmsgsSubsystemSequence) {
|
||||||
|
this.cminmsgsSubsystemSequence = cminmsgsSubsystemSequence;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCminmsgsSubsystemSubtype() {
|
||||||
|
return this.cminmsgsSubsystemSubtype;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCminmsgsSubsystemSubtype(String cminmsgsSubsystemSubtype) {
|
||||||
|
this.cminmsgsSubsystemSubtype = cminmsgsSubsystemSubtype;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCminmsgsSubsystemType() {
|
||||||
|
return this.cminmsgsSubsystemType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCminmsgsSubsystemType(String cminmsgsSubsystemType) {
|
||||||
|
this.cminmsgsSubsystemType = cminmsgsSubsystemType;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonEncoding;
|
import com.fasterxml.jackson.core.JsonEncoding;
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonParseException;
|
import com.fasterxml.jackson.core.JsonParseException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser.Feature;
|
||||||
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;
|
||||||
@@ -103,6 +104,10 @@ public class ExchangeServiceImpl implements IExchangeService {
|
|||||||
XmlMapper 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()));
|
||||||
|
|
||||||
|
//tofix: 暂时单独对BDPB做容错处理 ,可能为 jackson xml 的bug 或配置问题
|
||||||
|
xmlStr = xmlStr.replace("<BDPB>\n</BDPB>", "<BDPB></BDPB>");
|
||||||
|
|
||||||
return xmlMapper.readValue(xmlStr, MSG.class);
|
return xmlMapper.readValue(xmlStr, MSG.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ExchangeServiceException(e.getMessage(),e);
|
throw new ExchangeServiceException(e.getMessage(),e);
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.gzzn.omms.msgexchangeapi.service;
|
package com.gzzn.omms.msgexchangeapi.service;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -18,6 +16,7 @@ import com.fasterxml.jackson.core.JsonParseException;
|
|||||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||||
import com.gzzn.omms.msgexchangeapi.dao.CminmsgDao;
|
import com.gzzn.omms.msgexchangeapi.dao.CminmsgDao;
|
||||||
|
import com.gzzn.omms.msgexchangeapi.dao.CminmsgTestDao;
|
||||||
import com.gzzn.omms.msgexchangeapi.entity.msg.MESSAGESUBTYPES;
|
import com.gzzn.omms.msgexchangeapi.entity.msg.MESSAGESUBTYPES;
|
||||||
import com.gzzn.omms.msgexchangeapi.entity.msg.MESSAGETYPES;
|
import com.gzzn.omms.msgexchangeapi.entity.msg.MESSAGETYPES;
|
||||||
import com.gzzn.omms.msgexchangeapi.entity.msg.MSG;
|
import com.gzzn.omms.msgexchangeapi.entity.msg.MSG;
|
||||||
@@ -38,6 +37,8 @@ public class ExchangeServiceImplTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CminmsgDao cminmsgDao;
|
private CminmsgDao cminmsgDao;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CminmsgTestDao cminmsgTestDao;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testXmlToJson() throws JsonParseException, JsonMappingException, IOException {
|
public void testXmlToJson() throws JsonParseException, JsonMappingException, IOException {
|
||||||
@@ -94,27 +95,19 @@ public class ExchangeServiceImplTest {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testXmlToDNLDMsg() throws JsonParseException, JsonMappingException, IOException
|
public void testXmlToMsg() throws JsonParseException, JsonMappingException, IOException
|
||||||
{
|
{
|
||||||
String xml = cminmsgDao.findOne(300L).getCminmsgsClobMsg();
|
String xml = cminmsgTestDao.findOne(847328L).getCminmsgsClobMsg();//847325L
|
||||||
|
MSG msg = exchangeService.xmlToMsg(xml);
|
||||||
|
|
||||||
MSG dNLDMsg = exchangeService.xmlToMsg(xml);
|
System.out.println(JsonUtil.getStringWithNoneKey(msg));
|
||||||
String jsonString=JsonUtil.getString(dNLDMsg);
|
|
||||||
|
|
||||||
File file = new File("schd.json");
|
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
|
||||||
fos.write(jsonString.getBytes("utf-8"));
|
|
||||||
fos.close();
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println(jsonString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POJO 转xml字符串
|
* POJO 转xml字符串
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testObjectToXmlstr()
|
public void testMsgToXml()
|
||||||
{
|
{
|
||||||
Long nowtime = System.currentTimeMillis();
|
Long nowtime = System.currentTimeMillis();
|
||||||
MSG rqfdMsg = new MSGBuilder().
|
MSG rqfdMsg = new MSGBuilder().
|
||||||
|
|||||||
Reference in New Issue
Block a user