CaseClass2JsonHelper.scala 558 B

12345678910111213141516171819202122
  1. package com.winhc.bigdata.flink.implicits
  2. import org.apache.hadoop.hbase.client.Result
  3. import org.json4s.jackson.Serialization
  4. import org.json4s.{Formats, NoTypeHints}
  5. /**
  6. * @author: XuJiakai
  7. * @date: 2020/11/23 10:51
  8. */
  9. case class CaseClass2JsonHelper[A <: AnyRef](that: A) {
  10. def toJson()(implicit formats: Formats = Serialization.formats(NoTypeHints)): String = {
  11. if (that == null) {
  12. return null
  13. }
  14. that match {
  15. case result: Result =>
  16. result.toJsonString()
  17. case _ =>
  18. Serialization.write(that)
  19. }
  20. }
  21. }