Skip to content

Commit d66b7a8

Browse files
committed
fix: update zio-http to adhere to the json test requirement
That is "For each request, an object mapping the key message to Hello, World! must be instantiated."
1 parent 44428ec commit d66b7a8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

frameworks/Scala/zio-http/src/main/scala/Main.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import zio._
22
import zio.http._
33
import zio.http.netty.NettyConfig
44
import zio.http.netty.NettyConfig.LeakDetectionLevel
5+
import zio.json.EncoderOps
6+
57
import java.lang.{Runtime => JRuntime}
68

79
object Main extends ZIOAppDefault {
810

911
private val plainTextMessage: String = "hello, world!"
10-
private val jsonMessage: String = """{"message": "hello, world!"}"""
1112

1213
private val STATIC_SERVER_NAME = "zio-http"
1314
private val NUM_PROCESSORS = JRuntime.getRuntime.availableProcessors()
@@ -22,7 +23,7 @@ object Main extends ZIOAppDefault {
2223
Method.GET / "/json" ->
2324
Handler.fromResponse(
2425
Response
25-
.json(jsonMessage)
26+
.json(Payload(plainTextMessage).toJson)
2627
.addHeader(Header.Server(STATIC_SERVER_NAME)),
2728
),
2829
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import zio.json.{DeriveJsonCodec, JsonCodec}
2+
3+
case class Payload(message: String)
4+
object Payload {
5+
implicit val codec: JsonCodec[Payload] = DeriveJsonCodec.gen
6+
}

0 commit comments

Comments
 (0)