-
-
Notifications
You must be signed in to change notification settings - Fork 473
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
zio-http renders json of Map where keys are enum values as nested json array.
endpoints are made in declarative way and json codecs are made from Schema using zio.schema.codec.JsonCodec.zioJsonBinaryCodec
Example app below. You can run it, send a request and see response.
//> using scala 3.7.0
//> using dep dev.zio::zio:2.1.19
//> using dep dev.zio::zio-http:3.3.3
//> using dep dev.zio::zio-schema:1.7.3
//> using dep dev.zio::zio-schema-derivation:1.7.3
//> using dep dev.zio::zio-json:0.7.44
import zio.*
import zio.http.*
import zio.http.endpoint.Endpoint
import zio.schema.*
import zio.json.*
import zio.schema.codec.JsonCodec.zioJsonBinaryCodec
object SimpleServer extends ZIOAppDefault:
enum Property derives Schema:
case One, Two
// Define the response case class for our Map[String, String]
case class InfoResponse(data: Map[Property, String]) derives Schema
// Define the endpoint using declarative encoding
private val infoEndpoint =
Endpoint(RoutePattern.GET / "info")
.out[InfoResponse]
// Create the routes
private val routes: Routes[Any, Nothing] = Routes(
infoEndpoint.implement: _ =>
ZIO.succeed(InfoResponse(Map(
Property.One -> "one",
Property.Two -> "two",
)))
)
override def run: ZIO[Any, Throwable, Unit] =
Server.serve(routes).provide(Server.default)
curl localhost:8080/info
{"data":[["One","one"],["Two","two"]]}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working