use of top.tangyh.basic.interfaces.echo.EchoVO in project lamp-util by zuihou.
the class EchoServiceImpl method iterationWrite.
private void iterationWrite(Object obj, Map<LoadKey, Map<Serializable, Object>> typeMap, int depth, String... ignoreFields) {
// 解析方法上的注解,计算出obj对象中所有需要查询的数据
List<Field> fields = ClassManager.getFields(obj.getClass());
for (Field field : fields) {
FieldParam fieldParam = getFieldParam(obj, field, typeMap, innerTypeMap -> write(ReflectUtil.getFieldValue(obj, field), innerTypeMap, depth + 1, ignoreFields), ignoreFields);
if (fieldParam == null) {
continue;
}
Echo inField = fieldParam.getEcho();
Object actualValue = fieldParam.getActualValue();
Object originalValue = fieldParam.getOriginalValue();
String fieldName = fieldParam.getFieldName();
String ref = inField.ref();
LoadKey loadKey = fieldParam.getLoadKey();
Object echoValue = getEchoValue(inField, actualValue, originalValue, loadKey, typeMap);
if (echoValue == null) {
continue;
}
if (echoValue instanceof Map && ((Map<?, ?>) echoValue).isEmpty()) {
continue;
}
// feign 接口序列化 丢失类型
if (echoValue instanceof Map && !Object.class.equals(inField.beanClass())) {
echoValue = JsonUtil.parse(JsonUtil.toJson(echoValue), inField.beanClass());
}
if (StrUtil.isNotEmpty(ref)) {
ReflectUtil.setFieldValue(obj, ref, echoValue);
}
// 将新的值 反射 到指定字段
if (obj instanceof EchoVO) {
EchoVO vo = (EchoVO) obj;
vo.getEchoMap().put(fieldName, echoValue);
} else {
ReflectUtil.setFieldValue(obj, field, echoValue);
}
}
}
Aggregations