Spring Boot 2
在 application.yml
http:
converters:
preferred-json-mapper: gson
现在我用自定义设置编写类Gson
:
public class GsonUtil {
public static GsonBuilder gsonbuilder = new GsonBuilder();
public static Gson gson;
public static JsonParser parser = new JsonParser();
static {
// @Exclude -> to exclude specific field when serialize/deserilaize
gsonbuilder.addSerializationExclusionStrategy(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes field) {
return field.getAnnotation(Exclude.class) != null;
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
});
gsonbuilder.setPrettyPrinting();
gson = gsonbuilder.create();
}
}
我如何配置Spring Boot
我的自定义Gson
对象GsonUtil
?