SJsonHttpMessageConverter.kt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * ********************************************************************************************************************
  3. *
  4. * iFHS7.
  5. * ;BBMBMBMc rZMBMBR BMB
  6. * MBEr:;PBM, 7MBMMEOBB: BBB RBW
  7. * XK: BO SB. :SZ MBM. c;; ir BBM :FFr :SSF: ;xBMB:r iuGXv. i:. iF2;
  8. * DBBM0r. :D S7 ;XMBMB GMBMu. MBM: BMB MBMBBBMBMS WMBMBMBBK MBMBMBM BMBRBMBW .MBMBMBMBB
  9. * :JMRMMD .. , 1MMRM1; ;MBMBBR: MBM ;MB: BMB: MBM. RMBr sBMH BM0 UMB, BMB. KMBv
  10. * ;. XOW B1; :uM: 1RE, i .2BMBs rMB. MBO MBO JMB; MBB MBM BBS 7MBMBOBM: MBW :BMc
  11. * OBRJ.SEE MRDOWOR, 3DE:7OBM . ;BMB RMR7BM BMB MBB. BMB ,BMR .BBZ MMB rMB, BMM rMB7
  12. * :FBRO0D0 RKXSXPR. JOKOOMPi BMBSSWBMB; BMBB: MBMB0ZMBMS .BMBOXRBMB MBMDE RBM2;SMBM; MBB xBM2
  13. * iZGE O0SHSPO. uGZ7. sBMBMBDL :BMO OZu:BMBK, rRBMB0; ,EBMB xBMBr:ER. RDU :OO;
  14. * ,BZ, 1D0 RPSFHXR. xWZ .SMr . .BBB
  15. * :0BMRDG RESSSKR. 2WOMBW; BMBMR
  16. * i0BM: SWKHKGO MBDv
  17. * .UB OOGDM. MK, Copyright (c) 2015-2019. 斯伯坦机器人
  18. * , XMW ..
  19. * r All rights reserved.
  20. *
  21. * ********************************************************************************************************************
  22. */
  23. package com.sybotan.service.json
  24. import com.alibaba.fastjson.JSON
  25. import com.alibaba.fastjson.PropertyNamingStrategy
  26. import com.alibaba.fastjson.serializer.NameFilter
  27. import com.alibaba.fastjson.serializer.SerializeConfig
  28. import com.alibaba.fastjson.serializer.SerializerFeature
  29. import com.alibaba.fastjson.support.config.FastJsonConfig
  30. import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter
  31. import com.sybotan.base.utils.SJsonUtil
  32. import org.springframework.http.MediaType
  33. import springfox.documentation.swagger.web.SwaggerResource
  34. import springfox.documentation.swagger.web.UiConfiguration
  35. /**
  36. *
  37. */
  38. open class SJsonHttpMessageConverter : FastJsonHttpMessageConverter() {
  39. /**
  40. * 属性名命名规则
  41. */
  42. var propertyNamingStrategy : PropertyNamingStrategy
  43. get() = SJsonUtil.serializeConfig.propertyNamingStrategy
  44. set(value) {
  45. SJsonUtil.serializeConfig.propertyNamingStrategy = value
  46. } // Set propertyNamingStrategy
  47. init {
  48. val fastJsonConfig = FastJsonConfig()
  49. fastJsonConfig.dateFormat = JSON.DEFFAULT_DATE_FORMAT
  50. fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect)
  51. this.fastJsonConfig = fastJsonConfig;
  52. val nameFilter = NameFilter({ obj, name, value -> name })
  53. //val nameFilter = { `object`, name, value -> name }
  54. SJsonUtil.serializeConfig.addFilter(UiConfiguration::class.java, nameFilter)
  55. SJsonUtil.serializeConfig.addFilter(SwaggerResource::class.java, nameFilter)
  56. // serializeConfig.addFilter(MetricsEndpoint.MetricResponse::class.java, nameFilter)
  57. // serializeConfig.addFilter(EnvironmentEndpoint.EnvironmentDescriptor::class.java, nameFilter)
  58. fastJsonConfig.serializeConfig = SJsonUtil.serializeConfig
  59. val fastMediaTypes = ArrayList<MediaType>()
  60. fastMediaTypes.add(MediaType.APPLICATION_JSON)
  61. fastMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED)
  62. fastMediaTypes.add(MediaType.APPLICATION_OCTET_STREAM)
  63. fastMediaTypes.add(MediaType.TEXT_HTML)
  64. fastMediaTypes.add(MediaType("application", "vnd.spring-boot.actuator.v2+json"))
  65. this.supportedMediaTypes = fastMediaTypes;
  66. } // Init
  67. } // Class SJsonHttpMessageConverter