Bladeren bron

Fix 修复 翻译时异常导致json序列化结构体不符合预期

Yue 1 week geleden
bovenliggende
commit
68488532d0

+ 10 - 3
SERVER/VberAdminPlusV3/vber-common/vber-common-translation/src/main/java/com/vber/common/translation/core/handler/TranslationHandler.java

@@ -46,15 +46,22 @@ public class TranslationHandler extends JsonSerializer<Object> implements Contex
                 gen.writeNull();
                 return;
             }
-            Object result = trans.translation(value, translation.other());
-            gen.writeObject(result);
+            try {
+                Object result = trans.translation(value, translation.other());
+                gen.writeObject(result);
+            } catch (Exception e) {
+                log.error("翻译处理异常,type: {}, value: {}", translation.type(), value, e);
+                // 出现异常时输出原始值而不是中断序列化
+                gen.writeObject(value);
+            }
         } else {
             gen.writeObject(value);
         }
     }
 
     @Override
-    public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
+    public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property)
+            throws JsonMappingException {
         Translation translation = property.getAnnotation(Translation.class);
         if (Objects.nonNull(translation)) {
             this.translation = translation;