perf: 翻译防止递归导致的栈溢出
This commit is contained in:
+11
-1
@@ -151,7 +151,15 @@ public class TranslationAspect {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final Set<Object> processedObjects = new HashSet<>();
|
||||||
|
|
||||||
private Object translateObject(Object record, List<SysDictItemCore> listDict) {
|
private Object translateObject(Object record, List<SysDictItemCore> listDict) {
|
||||||
|
if (record == null || processedObjects.contains(record)) {
|
||||||
|
return record;
|
||||||
|
}
|
||||||
|
processedObjects.add(record);
|
||||||
|
|
||||||
|
try {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
String json;
|
String json;
|
||||||
try {
|
try {
|
||||||
@@ -171,7 +179,6 @@ public class TranslationAspect {
|
|||||||
for (Field field : oConvertUtils.getAllFields(record)) {
|
for (Field field : oConvertUtils.getAllFields(record)) {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
|
|
||||||
// 如果字段是复杂对象类型或者是List,进行递归翻译
|
|
||||||
if (isComplexObject(field.getType()) || List.class.isAssignableFrom(field.getType())) {
|
if (isComplexObject(field.getType()) || List.class.isAssignableFrom(field.getType())) {
|
||||||
Object nestedRecord;
|
Object nestedRecord;
|
||||||
try {
|
try {
|
||||||
@@ -214,6 +221,9 @@ public class TranslationAspect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
|
} finally {
|
||||||
|
processedObjects.remove(record);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isComplexObject(Class<?> type) {
|
private boolean isComplexObject(Class<?> type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user