Skip to content
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

Closed
tzxylao opened this issue May 11, 2020 · 5 comments
Closed

Comments

@tzxylao
Copy link

tzxylao commented May 11, 2020

image

@zycgit
Copy link
Collaborator

zycgit commented May 11, 2020

升级到 4.1.6,然后在界面上自定义。
image

第二个方式就是,resultprocess 拦截器
https://www.hasor.net/web/dataway/spi.html#resultprocess

@zycgit zycgit closed this as completed May 11, 2020
@tzxylao
Copy link
Author

tzxylao commented May 11, 2020

@zycgit 我想要实现的是返回结果忽略null字段,fastjson可以实现,就在我截图的图片位置,再给个配置参数就行,但在ResultProcessChainSpi这个调用链上没有response,返回值是对象,不能做这样的处理

@tzxylao
Copy link
Author

tzxylao commented May 11, 2020

   @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值字段也去掉,那么在此框架如何嵌入该功能

@zycgit
Copy link
Collaborator

zycgit commented May 11, 2020

那还是 open 这个 issue 把,我以为你只是单纯的结果改写。

@zycgit zycgit reopened this May 11, 2020
@zycgit zycgit changed the title 如何对返回结果进行自定义序列化? 返回结果进行自定义序列化?,比如 为空的列不输出。 May 11, 2020
@zycgit
Copy link
Collaborator

zycgit commented May 14, 2020

在 4.1.7 中会提供一个新的扩展接口 ResultSerializationChainSpi ,通过这个扩展接口可以实现自定义序列化。 可以提前 使用dev 分支来体验这一个功能。

same as #41

@zycgit zycgit closed this as completed May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants