File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed
frameworks/Scala/zio-http/src/main/scala Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -2,12 +2,13 @@ import zio._
22import zio .http ._
33import zio .http .netty .NettyConfig
44import zio .http .netty .NettyConfig .LeakDetectionLevel
5+ import zio .json .EncoderOps
6+
57import java .lang .{Runtime => JRuntime }
68
79object 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 )
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments