完善修正xml转json消息的问题。

This commit is contained in:
zhouxiunai
2018-12-20 10:13:32 +08:00
parent 8128b1c861
commit 2cf3a6ce23
2 changed files with 26 additions and 12 deletions
@@ -2,6 +2,7 @@ package com.gzzn.omms.msgexchangeapi.utils;
import java.io.IOException;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
@@ -22,6 +23,26 @@ public class JsonUtil {
}
} //end function
/**
* 获取json字符串去除值为null的key
* @param object
* @return json字符串
*/
public static String getStringWithNoneKey(Object object)
{
try {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
java.lang.String jsonStr;
jsonStr = ow.writeValueAsString(object);
return jsonStr;
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
} //end function
public static <T> T getObject(String str,Class<T> valueType) throws JsonParseException, JsonMappingException, IOException
{