9
Demo代码:
package com.test;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import java.io.Serializable;
/**
* 父类的方法有@JSONField,子类重写发现注解被丢失
*
* @author Created by 思伟 on 2020/4/20
*/
public class TestFastJson {
public static void main(String[] args) {
System.out.println(JSON.toJSONString(new B()));
}
interface Entity extends Serializable {
String getModule();
}
static class A implements Entity {
@Override
@JSONField(serialize = false)
public String getModule() {
return "AAA";
}
}
static class B extends A {
@Override
public String getModule() {
return this.getClass().getSimpleName();
}
}
}
输出结果:
{"module":"B"}