@Bean
public GsonBuilder gsonBuilder(List <GsonBuilderCustomizer> customizers) {
GsonBuilder builder = new GsonBuilder();
customizers.forEach((c) -> c.customize(builder));
builder
.serializeNulls()
.excludeFieldsWithoutExposeAnnotation()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
}
@AllArgsConstructor
@Getter
@Setter
@NoArgsConstructor
public class ModelStepInfo {
public boolean isSuccessed;
public String description;
public LocalDateTime startTime;
public LocalDateTime endTime;
}
gson.toJson(new ModelStepInfo(false, "dasdsada", LocalDateTime.now(), LocalDateTime.now()))
打印:{}版本:2.10.1为什么它出来时是空的?有解决办法吗?我不知道怎么了
1条答案
按热度按时间yyhrrdl81#
问题很可能是您使用的是
excludeFieldsWithoutExposeAnnotation()
,但您的字段中没有一个带有@Expose
注解的字段,因此所有字段都被忽略了。