|
|
@@ -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; |
|
|
|
} |
|
|
|
} |