打印接受到的报文内容
修复 feign 调用时间错乱问题 完善ARRE 实际起飞时间 实际到达时间为null 问题
正在显示
2 个修改的文件
包含
84 行增加
和
1 行删除
| @@ -82,6 +82,12 @@ | @@ -82,6 +82,12 @@ | ||
| 82 | <version>5.2.0.BUILD-SNAPSHOT</version> | 82 | <version>5.2.0.BUILD-SNAPSHOT</version> |
| 83 | <scope>compile</scope> | 83 | <scope>compile</scope> |
| 84 | </dependency> | 84 | </dependency> |
| 85 | + <dependency> | ||
| 86 | + <groupId>com.alibaba</groupId> | ||
| 87 | + <artifactId>fastjson</artifactId> | ||
| 88 | + <version>1.2.73</version> | ||
| 89 | + <scope>compile</scope> | ||
| 90 | + </dependency> | ||
| 85 | </dependencies> | 91 | </dependencies> |
| 86 | 92 | ||
| 87 | <build> | 93 | <build> |
| @@ -98,4 +104,4 @@ | @@ -98,4 +104,4 @@ | ||
| 98 | </plugins> | 104 | </plugins> |
| 99 | </build> | 105 | </build> |
| 100 | 106 | ||
| 101 | -</project> | ||
| 107 | +</project> |
src/main/java/com/tianbo/util/XmlJson.java
0 → 100644
| 1 | +package com.tianbo.util; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONArray; | ||
| 4 | +import com.alibaba.fastjson.JSONObject; | ||
| 5 | +import org.dom4j.Attribute; | ||
| 6 | +import org.dom4j.Element; | ||
| 7 | + | ||
| 8 | +import java.util.List; | ||
| 9 | + | ||
| 10 | +import static org.apache.commons.lang.StringUtils.isEmpty; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * @author shenhl | ||
| 14 | + * <p> | ||
| 15 | + * 2022/1/11/14:39 | ||
| 16 | + */ | ||
| 17 | +public class XmlJson { | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * xml转json | ||
| 21 | + * @param element | ||
| 22 | + * @param json | ||
| 23 | + */ | ||
| 24 | + public static void dom4j2Json(Element element, JSONObject json){ | ||
| 25 | + //如果是属性 | ||
| 26 | + for(Object o:element.attributes()){ | ||
| 27 | + Attribute attr=(Attribute)o; | ||
| 28 | + if(!isEmpty(attr.getValue())){ | ||
| 29 | + json.put("@"+attr.getName(), attr.getValue()); | ||
| 30 | + } | ||
| 31 | + } | ||
| 32 | + List<Element> chdEl=element.elements(); | ||
| 33 | + if(chdEl.isEmpty()&&!isEmpty(element.getText())){//如果没有子元素,只有一个值 | ||
| 34 | + json.put(element.getName(), element.getText()); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + for(Element e:chdEl){//有子元素 | ||
| 38 | + if(!e.elements().isEmpty()){//子元素也有子元素 | ||
| 39 | + JSONObject chdjson=new JSONObject(); | ||
| 40 | + dom4j2Json(e,chdjson); | ||
| 41 | + Object o=json.get(e.getName()); | ||
| 42 | + if(o!=null){ | ||
| 43 | + JSONArray jsona=null; | ||
| 44 | + if(o instanceof JSONObject){//如果此元素已存在,则转为jsonArray | ||
| 45 | + JSONObject jsono=(JSONObject)o; | ||
| 46 | + json.remove(e.getName()); | ||
| 47 | + jsona=new JSONArray(); | ||
| 48 | + jsona.add(jsono); | ||
| 49 | + jsona.add(chdjson); | ||
| 50 | + } | ||
| 51 | + if(o instanceof JSONArray){ | ||
| 52 | + jsona=(JSONArray)o; | ||
| 53 | + jsona.add(chdjson); | ||
| 54 | + } | ||
| 55 | + json.put(e.getName(), jsona); | ||
| 56 | + }else{ | ||
| 57 | + if(!chdjson.isEmpty()){ | ||
| 58 | + json.put(e.getName(), chdjson); | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + | ||
| 63 | + }else{//子元素没有子元素 | ||
| 64 | + for(Object o:element.attributes()){ | ||
| 65 | + Attribute attr=(Attribute)o; | ||
| 66 | + if(!isEmpty(attr.getValue())){ | ||
| 67 | + json.put("@"+attr.getName(), attr.getValue()); | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + if(!e.getText().isEmpty()){ | ||
| 71 | + json.put(e.getName(), e.getText()); | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | +} |
-
请 注册 或 登录 后发表评论