mirror of
https://github.com/alibaba/arthas.git
synced 2026-10-21 04:22:16 +00:00
mcp use ObjectView format default
This commit is contained in:
@@ -4,7 +4,9 @@ import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONFactory;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.filter.ValueFilter;
|
||||
import com.taobao.arthas.core.GlobalOptions;
|
||||
import com.taobao.arthas.core.command.model.ObjectVO;
|
||||
import com.taobao.arthas.core.view.ObjectView;
|
||||
import com.taobao.arthas.mcp.server.util.JsonParser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -57,14 +59,39 @@ public class McpObjectVOFilter implements ValueFilter {
|
||||
return "null";
|
||||
}
|
||||
|
||||
return objectVO.needExpand() ? drawObjectView(innerObject) : objectToString(innerObject);
|
||||
if (objectVO.needExpand()) {
|
||||
// 根据 GlobalOptions.isUsingJson 配置决定输出格式
|
||||
if (GlobalOptions.isUsingJson) {
|
||||
return drawJsonView(innerObject);
|
||||
} else {
|
||||
return drawObjectView(objectVO);
|
||||
}
|
||||
} else {
|
||||
return objectToString(innerObject);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to handle ObjectVO: {}", e.getMessage());
|
||||
return "{\"error\":\"ObjectVO serialization failed\"}";
|
||||
}
|
||||
}
|
||||
|
||||
private String drawObjectView(Object object) {
|
||||
/**
|
||||
* 使用 ObjectView 输出对象结构
|
||||
*/
|
||||
private String drawObjectView(ObjectVO objectVO) {
|
||||
try {
|
||||
ObjectView objectView = new ObjectView(objectVO);
|
||||
return objectView.draw();
|
||||
} catch (Exception e) {
|
||||
logger.debug("ObjectView serialization failed, using toString: {}", e.getMessage());
|
||||
return objectToString(objectVO.getObject());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用 JSON 格式输出对象
|
||||
*/
|
||||
private String drawJsonView(Object object) {
|
||||
try {
|
||||
JSONWriter.Context context = JSONFactory.createWriteContext();
|
||||
context.setMaxLevel(4097);
|
||||
|
||||
Reference in New Issue
Block a user