Browse Source

对于xml格式的消息 使用toString会收尾拼接“ 导致后续转化异常

master
yechuan 1 year ago
parent
commit
4da1a259a9
2 changed files with 27 additions and 1 deletions
  1. +26
    -0
      transformer/src/main/java/work/xuye/transformer/transformer/JsonDataTransformer.java
  2. +1
    -1
      transformer/src/main/java/work/xuye/transformer/transformer/ResDataTransformer.java

+ 26
- 0
transformer/src/main/java/work/xuye/transformer/transformer/JsonDataTransformer.java View File

@@ -0,0 +1,26 @@
package work.xuye.transformer.transformer;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
* @author yechuan
* @since 2023/8/11 11:55
**/
@Slf4j
@Component("jsonData")
public class JsonDataTransformer implements MessageTransformer{
@Override
public String transform(String message, String seedUrl) {
JsonObject res = JsonParser.parseString(message).getAsJsonObject();
boolean hasData = res.has("data");
if (hasData) {
return res.get("data").toString();
} else {
log.warn("resData transform failed, res not has data, res: {}", res);
}
return null;
}
}

+ 1
- 1
transformer/src/main/java/work/xuye/transformer/transformer/ResDataTransformer.java View File

@@ -20,7 +20,7 @@ public class ResDataTransformer implements MessageTransformer {
JsonObject res = JsonParser.parseString(json).getAsJsonObject();
boolean hasData = res.has("data");
if (hasData) {
return res.get("data").toString();
return res.get("data").getAsString();
} else {
log.warn("resData transform failed, res not has data, res: {}", res);
}


Loading…
Cancel
Save