question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possibility to read raw JSON

See original GitHub issue

Hi, I have a small question:

Is there a possibility to parse the following JSON to the following case class?

{"param1": 1, "param2": "test", "payload": {"param3": "test", "json": {"param4": 1}}, "param4: "test"}

case class Test(param1: Int, param2: String, payload: String)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
plokhotnyukcommented, Sep 25, 2019

@mindartyr you can use the following codec for Seq[Array[Byte]] like here:

object Example01 {
  implicit val seqOfRawValCodec: JsonValueCodec[Seq[Array[Byte]]] = {
    implicit val rawValCodec: JsonValueCodec[Array[Byte]] = new JsonValueCodec[Array[Byte]] {
      override def decodeValue(in: JsonReader, default: Array[Byte]): Array[Byte] = in.readRawValAsBytes()

      override def encodeValue(x: Array[Byte], out: JsonWriter): Unit = out.writeRawVal(x)

      override val nullValue: Array[Byte] = new Array[Byte](0)
    }

    JsonCodecMaker.make[Seq[Array[Byte]]](CodecMakerConfig())
  }

  def main(args: Array[String]): Unit = {
    val data = readFromArray("""[{"key1": "val2"}, {"key1": "val2"}]""".getBytes("UTF-8"))
    val json = writeToArray(data)

    println(data)
    println(new String(json, "UTF-8"))
  }
}

It will print:

List([B@6fffcba5, [B@34340fab)
[{"key1": "val2"} {"key1": "val2"}]
0reactions
mindarturcommented, Sep 25, 2019

@plokhotnyuk thanks a lot! Will try

Read more comments on GitHub >

github_iconTop Results From Across the Web

Read content from file in raw json request body - Help - Postman
I want to test my server via sending raw json data. One of the values of my request body is a really big...
Read more >
How to read the raw json post body before hitting the ...
I have planned to execute this requirement by reading entire json raw body data in a model binder , deserialize it and setting...
Read more >
Raw JSON text format - Minecraft Wiki - Fandom
Raw JSON text is the format Minecraft uses to send and display rich text to players. It can also be sent by players...
Read more >
JSON: What It Is, How It Works, & How to Use It - Copter Labs
JSON is short for JavaScript Object Notation, and is a way to store information in an organized, easy-to-access manner. In a nutshell, it...
Read more >
JSON file | Databricks on AWS
You can read JSON files in single-line or multi-line mode. In single-line mode, a file can be split into many parts and read...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found