fastjson FieldInfo.set() not actually works.

5n0oy7gb  于 2021-11-27  发布在  Java
关注(0)|答案(4)|浏览(259)

com.alibaba.fastjson.util.FieldInfo:433

public void set(Object javaObject, Object value) throws IllegalAccessException, InvocationTargetException {
        if (method != null) {
            method.invoke(javaObject, new Object[] { value });
            return;
        }

        field.set(javaObject, value);
    }

Here method actually points to the field's getter. Hence it doesn't work as its name stated. Invoking it will result to a java.lang.IllegalArgumentException: wrong number of arguments.

h79rfbju

h79rfbju1#

FieldInfo use to serializer invoke getter & deserializer invoke setter, it no problem. can you gives a testcase reproduce this problem?

os8fio9y

os8fio9y2#

List<FieldInfo> lfi = TypeUtils.computeGetters(clazz, null, null, false);

FieldInfo fi = lfi.get(arbitrary);              // ... for example, `dname`

System.out.println(value);                      // "喵喵喵"
System.out.println(fi.fieldClass);              // class java.lang.String 
System.out.println(fi.method);                  // public java.lang.String com.kakakj.cafune.user.model.UserBase.getDname()

fi.set(object, value);                          // boom!

, where clazz is a standard POJO and object is an instance of it.

ppcbkaq5

ppcbkaq53#

it's internal api, can not directly invoke!

nnt7mjpx

nnt7mjpx4#

@wenshao I know, but it's still a flaw. ( ˘•ω•˘ )

相关问题