You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2019/12/30 16:31:16 UTC

[GitHub] [servicecomb-java-chassis] zhufeizzz opened a new issue #1505: 怎么自定义Jackson的ObjectMapper?

zhufeizzz opened a new issue #1505: 怎么自定义Jackson的ObjectMapper?
URL: https://github.com/apache/servicecomb-java-chassis/issues/1505
 
 
   我想做两件事:
   1、支持org.json的转换
   2、把所有Rest接口默认使用下划线方式
   
   没找到相关文档,扒代码找到如下方式设置:
   ```
   JsonUtils.OBJ_MAPPER.registerModule(new JsonOrgModule());
   JsonUtils.OBJ_MAPPER.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
           
   RestObjectMapperFactory.getRestObjectMapper().registerModule(new JsonOrgModule()); 
   RestObjectMapperFactory.getRestObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
   ```
   
   我试了下org.json支持没问题,但是SNAKE_CASE会导致ServiceComb无法启动,提示微服务命名格式不对。
   
   我这是标准的扩展ObjectMapper的方式吗?扩展的时候到底有什么限制?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #1505: 怎么自定义Jackson的ObjectMapper?

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #1505: 怎么自定义Jackson的ObjectMapper?
URL: https://github.com/apache/servicecomb-java-chassis/issues/1505#issuecomment-569840277
 
 
   你需要使用RestObjectMapperFactory setConsumerWriterMapper 和 setDefaultRestObjectMapper覆盖AbstractRestObjectMapper,需要先自定义一个实现。 
   
   通常,不推荐自定义,这个会导致不同的系统之间相互协作出现问题,或者在a -> b -> c等场景下,容易出现错误。 仅仅在需要兼容的情况下,做适当的处理,否则建议改善接口设计,遵循标准行为是推荐的方式。 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [servicecomb-java-chassis] zhufeizzz commented on issue #1505: 怎么自定义Jackson的ObjectMapper?

Posted by GitBox <gi...@apache.org>.
zhufeizzz commented on issue #1505: 怎么自定义Jackson的ObjectMapper?
URL: https://github.com/apache/servicecomb-java-chassis/issues/1505#issuecomment-569845820
 
 
   1、有没有文档定义哪些行为能改,判断原则有吗?比如我现在改了,目测能运行,但是不知道有没有什么坑。
   2、setConsumerWriterMapper是什么场景用的,调试时没看到有地方使用。

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services