package com.qianwen.core.coderule.util; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.PropertyNamingStrategy; import java.io.IOException; import java.lang.reflect.Field; import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; import com.qianwen.core.coderule.annotation.CodeRule; import com.qianwen.core.tool.jackson.JsonUtil; /* loaded from: blade-starter-coderule-9.3.0.0-SNAPSHOT.jar:org/springblade/core/coderule/util/CodeRuleHelper.class */ public class CodeRuleHelper { public static Map toUnderlineJSONString(Object object) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return JsonUtil.toMap(mapper.writeValueAsString(object)); } public static T toSnakeObject(String json, Class clazz) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); T reqJson = (T) mapper.readValue(json, clazz); return reqJson; } public static Map getDeclaredFieldsInfoByFieldName(Object instance) { Map map = new HashMap<>(); Class clazz = instance.getClass(); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { try { Field field2 = clazz.getDeclaredField(field.getName()); field2.setAccessible(true); map.put(field2.getName(), field2.get(instance)); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e2) { e2.printStackTrace(); } } return map; } /* JADX WARN: Multi-variable type inference failed */ public static Map getDeclaredFieldsInfoByAnnotation(Object instance) { Map map = new HashMap<>(); Class clazz = instance.getClass(); Field[] fields = clazz.getDeclaredFields(); try { map = toUnderlineJSONString(instance); for (Field field : fields) { Field field2 = clazz.getDeclaredField(field.getName()); field2.setAccessible(true); boolean annotationPresent = field2.isAnnotationPresent(CodeRule.class); if (annotationPresent) { String name = ((CodeRule) field2.getAnnotation(CodeRule.class)).code(); map.put(name, field2.get(instance)); } } } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e2) { e2.printStackTrace(); } catch (JsonProcessingException e3) { e3.printStackTrace(); } return map; } public static String getRealData(BigDecimal num) { if (num == null) { return ""; } String value = num.stripTrailingZeros().toPlainString(); return value; } }