Created
May 9, 2018 10:33
-
-
Save deepankar14693/0eeb9072f5fa7074c2d6450fca07c0c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.json4s.{DefaultFormats, Formats, JNothing, JValue} | |
import org.json4s.native.JsonMethods.{parse => jParser} | |
import org.json4s.native.Serialization | |
import org.json4s.native.Serialization.{write => jWrite} | |
trait JsonHelper extends { | |
val EMPTY_STRING = "" | |
implicit val serialization: Serialization.type = Serialization | |
implicit val formats: Formats = DefaultFormats | |
def write[T <: AnyRef](value: T): String = jWrite(value) | |
protected def parse(value: String): JValue = jParser(value) | |
implicit protected def extractOrEmptyString(json: JValue): String = { | |
json match { | |
case JNothing => EMPTY_STRING | |
case data => data.extract[String] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment