springmvc fastjson定制化输出

fastjson定制化输出:
https://github.com/alibaba/fastjson/wiki/JSONField
试了几个都不行,可能是我框架 问题,这里是我现在的方法

1、entity

@JSONField(serializeUsing = ModelValueSerializer.class)
    public Long getId() {
        return id;
    }

2、ModelValueSerializer
public class ModelValueSerializer implements ObjectSerializer {
    
    @Override
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType,
                      int features) throws IOException {
        Long value = (Long) object;
        String text = value + "";
        serializer.write(text);
    }

}


这里还有其他方式

https://gitee.com/baomidou/mybatis-plus/issues/IFAOU

你可能感兴趣的:(springMvc,spring)