|
@@ -1,5 +1,6 @@
|
|
|
package com.winhc.bigdata.spark.implicits
|
|
|
|
|
|
+import com.winhc.bigdata.spark.implicits.CaseClass2JsonHelper._
|
|
|
import org.apache.commons.lang3.StringUtils
|
|
|
|
|
|
/**
|
|
@@ -11,7 +12,7 @@ object MapHelper {
|
|
|
|
|
|
implicit class MapEnhancer(map: Map[String, String]) extends Serializable {
|
|
|
def toJson(fields: Seq[String]): String = {
|
|
|
- val content = fields.map(item => {
|
|
|
+ val content = fields.map(item => {
|
|
|
if (item.contains("->")) {
|
|
|
val Array(key, keyAlias) = item.split("->")
|
|
|
s"${getValueOrNull(keyAlias)}:${getValueOrNull(map(key))}"
|
|
@@ -25,9 +26,9 @@ object MapHelper {
|
|
|
|
|
|
private def getValueOrNull(value: String): String = {
|
|
|
if (StringUtils.isNotBlank(value)) {
|
|
|
- "\"" + value + "\""
|
|
|
+ value.toJson()
|
|
|
} else {
|
|
|
- "\"\""
|
|
|
+ "".toJson()
|
|
|
}
|
|
|
}
|
|
|
|