Skip to content

Commit f8051a1

Browse files
committed
Added codec for IntOrBoolean.
1 parent 18b7332 commit f8051a1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

01-domain/src/main/scala/camundala/domain/exports.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ given InOutCodec[IntOrString] = CirceCodec.from(
113113
type IntOrString = Int | String
114114
given ApiSchema[IntOrString] = Schema.derivedUnion
115115

116+
type IntOrBoolean = Int | Boolean
117+
118+
given ApiSchema[IntOrBoolean] = Schema.derivedUnion
119+
given InOutCodec[IntOrBoolean] = CirceCodec.from(
120+
new Decoder[IntOrBoolean]:
121+
final def apply(c: HCursor): Decoder.Result[IntOrBoolean] =
122+
if c.value.isBoolean
123+
then c.as[Boolean]
124+
else c.as[Int]
125+
,
126+
new Encoder[IntOrBoolean]:
127+
final def apply(a: IntOrBoolean): Json = a match
128+
case s: Boolean => Json.fromBoolean(s)
129+
case i: Int => Json.fromInt(i)
130+
)
131+
116132
case class NoInput()
117133
object NoInput:
118134
given ApiSchema[NoInput] = deriveApiSchema

0 commit comments

Comments
 (0)