fix(mms-mapping): 修复XML资源配置加载和JSON映射提取问题
- 删除冗余注释,优化代码可读性 - 增强extractMappingJson方法中的类型安全处理,支持字符串和对象类型的mappingJson字段 - 添加对象类型转换逻辑,确保返回正确格式的JSON字符串
This commit is contained in:
@@ -180,7 +180,7 @@ public class IcdToXmlTaskAppService {
|
|||||||
* 加载 XML 模板和规则文件。
|
* 加载 XML 模板和规则文件。
|
||||||
*/
|
*/
|
||||||
private XmlResourceContext loadXmlResources() throws Exception {
|
private XmlResourceContext loadXmlResources() throws Exception {
|
||||||
return loadXmlResources(1);
|
return loadXmlResources(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private XmlResourceContext loadXmlResources(Integer configType) throws Exception {
|
private XmlResourceContext loadXmlResources(Integer configType) throws Exception {
|
||||||
|
|||||||
@@ -127,7 +127,6 @@ public class JsonToXmlDebugRunner {
|
|||||||
*/
|
*/
|
||||||
private static String extractMappingJson(String jsonContent, ObjectMapper objectMapper) {
|
private static String extractMappingJson(String jsonContent, ObjectMapper objectMapper) {
|
||||||
try {
|
try {
|
||||||
// 尝试解析为对象,看是否包含 mappingJson 字段
|
|
||||||
if (jsonContent.trim().startsWith("{")) {
|
if (jsonContent.trim().startsWith("{")) {
|
||||||
java.util.Map<String, Object> jsonMap = objectMapper.readValue(
|
java.util.Map<String, Object> jsonMap = objectMapper.readValue(
|
||||||
jsonContent,
|
jsonContent,
|
||||||
@@ -137,7 +136,11 @@ public class JsonToXmlDebugRunner {
|
|||||||
if (jsonMap.containsKey("mappingJson")) {
|
if (jsonMap.containsKey("mappingJson")) {
|
||||||
Object mappingJsonObj = jsonMap.get("mappingJson");
|
Object mappingJsonObj = jsonMap.get("mappingJson");
|
||||||
if (mappingJsonObj != null) {
|
if (mappingJsonObj != null) {
|
||||||
return mappingJsonObj.toString();
|
if (mappingJsonObj instanceof String) {
|
||||||
|
return (String) mappingJsonObj;
|
||||||
|
} else {
|
||||||
|
return objectMapper.writeValueAsString(mappingJsonObj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user