Commit 6a6fe0d3 authored by Administrator's avatar Administrator

custom for specialViewer

parent fd811797
...@@ -166,6 +166,13 @@ public class ForceFiledViewer { ...@@ -166,6 +166,13 @@ public class ForceFiledViewer {
return subRet; return subRet;
} }
String className = input.getClass().getName(); String className = input.getClass().getName();
Function function = specialViewer.get(className);
if (function != null) {
//某些特殊的dump规则,不如jodaTime,dump内容没有意义
return function.apply(input);
}
if (skipDumpPackage.isSubPackage(className) && !forceDumpPackage.isSubPackage(className)) { if (skipDumpPackage.isSubPackage(className) && !forceDumpPackage.isSubPackage(className)) {
//框架内部对象,不抽取,这可能导致递归过深,而且没有意义 //框架内部对象,不抽取,这可能导致递归过深,而且没有意义
return null; return null;
...@@ -279,10 +286,11 @@ public class ForceFiledViewer { ...@@ -279,10 +286,11 @@ public class ForceFiledViewer {
return fields; return fields;
} }
private static final ConcurrentMap<Class, Map<String, Field>> fieldCache = new ConcurrentHashMap<>(); private static final ConcurrentMap<Class<?>, Map<String, Field>> fieldCache = new ConcurrentHashMap<>();
private static PackageTrie forceDumpPackage = new PackageTrie(); private static PackageTrie forceDumpPackage = new PackageTrie();
private static PackageTrie skipDumpPackage = new PackageTrie(); private static PackageTrie skipDumpPackage = new PackageTrie();
private static PackageTrie skipTranslatePackage = new PackageTrie(); private static PackageTrie skipTranslatePackage = new PackageTrie();
private static Map<String, Function> specialViewer = new ConcurrentHashMap<>();
public static void addForceViewConfig(String basePackage) { public static void addForceViewConfig(String basePackage) {
forceDumpPackage.addToTree(basePackage); forceDumpPackage.addToTree(basePackage);
...@@ -296,6 +304,22 @@ public class ForceFiledViewer { ...@@ -296,6 +304,22 @@ public class ForceFiledViewer {
skipTranslatePackage.addToTree(basePackage); skipTranslatePackage.addToTree(basePackage);
} }
public static void addSpecialViewer(String clazz, Function transformFunction) {
specialViewer.put(clazz, transformFunction);
}
public interface Function {
Object apply(Object o);
}
private static Function ToString = o -> {
if (o == null) {
return null;
}
return o.toString();
};
static { static {
addSkipViewConfig("android"); addSkipViewConfig("android");
addSkipViewConfig("com.android"); addSkipViewConfig("com.android");
...@@ -322,5 +346,9 @@ public class ForceFiledViewer { ...@@ -322,5 +346,9 @@ public class ForceFiledViewer {
addSKipTranslateConfig("com.alibaba.fastjson"); addSKipTranslateConfig("com.alibaba.fastjson");
addSKipTranslateConfig("org.json"); addSKipTranslateConfig("org.json");
addSKipTranslateConfig("com.google.gson"); addSKipTranslateConfig("com.google.gson");
addSpecialViewer("org.joda.time.DateTime", ToString);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment