Event
.as[List[MarketEvent]]
?
MarketEvent
bit, but you can discriminate on the type
property to determine which decoder to use
Array[T]
all of the sudden.
Hey guys I have a really basic question,
for a basic webhook thing I'd like to parse json partially and keep a field as string
val rawJson: String ="""
{
"url": "http://bar",
"method": "GET",
"body": "{"tucsfoo":""}",
"cronExpression": "* * * * *"
}
"""
case class CronTask(url: String, method: String, body: String, cronExpression: String)
object CronTask {
import argonaut._, Argonaut._
implicit def PersonCodecJson: CodecJson[CronTask] =
casecodec4(CronTask.apply, CronTask.unapply)("url", "method", "body", "cronExpression")
}
I would love to get back the body as a string, how would i do that?
List[CursorOp]
def flatMapCursor(f: HCursor => DecodeResult[HCursor]): DecodeJson[A]
looks promising, but I'm not quite sure if and how could it be utilized.
Json
.obj()
.as[Option[String]](DecodeJson[Option[String]] { hcursor =>
(hcursor --\ "lol").as[Option[String]]
}) shouldBe DecodeResult.ok(None)
DecodeResult(Left((Attempt to decode value on failed cursor.,CursorHistory(List(El(CursorOpDownField(lol),false)))))) was not equal to DecodeResult(Right(None)) (OrderJsonSpec.scala:30)
"argonaut-jawn" % "6.2.2"
JAR includes only the manifest? Am I missing something? See e.g. http://central.maven.org/maven2/io/argonaut/argonaut-jawn_2.11/6.2.2/argonaut-jawn_2.11-6.2.2.jar
Hi - is argonaut 6.2.2
backwards compatible with 6.2
, i.e. it's truly a "patch" version bump?
Nevermind, I see:
All minor releases (from 6.0 onwards) are binary compatible, i.e. 6.1.x stream are drop in replacements, and the same will be true for 6.2.x, but going from 6.1 to 6.2 may require changes or recompilation.
lift-json
to argonaut
so I can take advantage of Scala Native support and 2.13
support. The is the code I'm trying to convert. https://github.com/ekrich/sconfig/blob/master/sconfig/src/test/scala/org/ekrich/config/impl/JsonTest.scala#L60-L92
toJson
I'm having more luck with. I'm have difficulty with JNumber
pattern matching. I have somelike this.
private[this] def fromJson(json: Json): AbstractConfigValue = {
import scala.collection.JavaConverters._
json match {
case JObject(fields) =>
val m = new HashMap[String, AbstractConfigValue]()
fields.toMap.foreach({ field =>
m.put(field._1, fromJson(field._2))
})
new SimpleConfigObject(fakeOrigin(), m)
case JArray(values) =>
new SimpleConfigList(fakeOrigin(), values.map(fromJson(_)).asJava)
case JNumber(i) =>
i match {
case JsonLong(v) => longValue(v)
case JNumber(v) => i.
}
jNull
and or friends.
Option
of that type.
java.time._
types: implicit val codec: JsonValueCodec[Map[String, List[ZonedDateTime]]] = JsonCodecMaker.make(CodecMakerConfig())