-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
返回结果进行自定义序列化?,比如 为空的列不输出。 #41
Comments
第二个方式就是,resultprocess 拦截器 |
@zycgit 我想要实现的是返回结果忽略null字段,fastjson可以实现,就在我截图的图片位置,再给个配置参数就行,但在ResultProcessChainSpi这个调用链上没有response,返回值是对象,不能做这样的处理 |
@Bean
@Primary
@ConditionalOnMissingBean(ObjectMapper.class)
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
// 忽略null字段
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
return objectMapper;
}
@JsonIgnore
private Object source; 其实就是这样,本来我用jackson序列化,返回结果会自动去掉该字段,且null值字段也去掉,那么在此框架如何嵌入该功能 |
Closed
那还是 open 这个 issue 把,我以为你只是单纯的结果改写。 |
在 4.1.7 中会提供一个新的扩展接口 ResultSerializationChainSpi ,通过这个扩展接口可以实现自定义序列化。 可以提前 使用dev 分支来体验这一个功能。 same as #41 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: