Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.8.6
beffe00c80d156286982b58a0f5dcbbfcb7bb614
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version = "3.8.1"
version = "3.8.6"
runner.dialect = scala3
maxColumn = 120
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ object Decoder:
if v == null
then None
else Some(decoder.decode(v))


given SeqDecoderCodec: [T: DataDecoder as decoder] => DataDecoder[Seq[T]] :
given SeqDecoderCodec: [T: DataDecoder as decoder] => DataDecoder[Seq[T]]:
override def decode(v: Any): Seq[T] =
v match
case arr: JsonArray =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ object Encoder:
given DataEncoder[Date]:
override def encode(v: Date): Any = v

given OptionEncoderCodec : [T: DataEncoder as encoder] => DataEncoder[Option[T]]:
given OptionEncoderCodec: [T: DataEncoder as encoder] => DataEncoder[Option[T]]:
override def encode(v: Option[T]): Any =
v.map(encoder.encode).orNull

Expand All @@ -104,7 +104,6 @@ object Encoder:
override def encode(vs: Set[T]): Any =
vs.map(encoder.encode)


inline def typ[T]: EncoderCreator[T] =
new Encoder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class ArrayProduct(arr: Array[Any]) extends Product:

override def canEqual(that: Any): Boolean = that match
case ap: ArrayProduct if ap.productArity == productArity => true
case _ => false
case _ => false
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ object JsonConverter:

override def fromJson(value: Any): Int =
value match
case _: Int => value.asInstanceOf[Int]
case _: Long => value.asInstanceOf[Long].toInt
case _: Int => value.asInstanceOf[Int]
case _: Long => value.asInstanceOf[Long].toInt
case _: Short => value.asInstanceOf[Short].toInt
case _ => throw new JsonCodecException(s"can't parse ${value} to Int")
case _ => throw new JsonCodecException(s"can't parse ${value} to Int")
}

given longConv: JsonConverter[Long] = new JsonConverter[Long] {
Expand All @@ -58,13 +58,13 @@ object JsonConverter:

override def fromJson(value: Any): Long =
value match
case _: Int => value.asInstanceOf[Int].toLong
case _: Long => value.asInstanceOf[Long]
case _: Int => value.asInstanceOf[Int].toLong
case _: Long => value.asInstanceOf[Long]
case _: Short => value.asInstanceOf[Short].toLong
case _ => throw new JsonCodecException(s"can't parse ${value} to Int")
case _ => throw new JsonCodecException(s"can't parse ${value} to Int")
}

given stringConv: JsonConverter[String]= new JsonConverter[String] {
given stringConv: JsonConverter[String] = new JsonConverter[String] {
extension (a: String)
override def toJsonValue: Json = JsonValue(a)
override def toJson: String = a
Expand Down Expand Up @@ -96,10 +96,10 @@ object JsonConverter:

override def fromJson(value: Any): Short =
value match
case _: Int => value.asInstanceOf[Int].toShort
case _: Long => value.asInstanceOf[Long].toShort
case _: Int => value.asInstanceOf[Int].toShort
case _: Long => value.asInstanceOf[Long].toShort
case _: Short => value.asInstanceOf[Short]
case _ => throw new JsonCodecException(s"can't parse ${value} to Short")
case _ => throw new JsonCodecException(s"can't parse ${value} to Short")
}

given doubleConv: JsonConverter[Double] = new JsonConverter[Double] {
Expand All @@ -110,7 +110,7 @@ object JsonConverter:
override def fromJson(value: Any): Double =
value match
case _: Double => value.asInstanceOf[Double]
case _: Float => value.asInstanceOf[Float].toDouble
case _: Float => value.asInstanceOf[Float].toDouble
case _ =>
throw new JsonCodecException(s"can't parse ${value} to Double")
}
Expand All @@ -123,7 +123,7 @@ object JsonConverter:
override def fromJson(value: Any): Float =
value match
case _: Double => value.asInstanceOf[Double].toFloat
case _: Float => value.asInstanceOf[Float]
case _: Float => value.asInstanceOf[Float]
case _ =>
throw new JsonCodecException(s"can't parse ${value} to Float")
}
Expand All @@ -140,7 +140,7 @@ object JsonConverter:
throw new JsonCodecException(s"can't parse ${value} to Null")
}

inline given dateConv: JsonConverter[Date] = new JsonConverter[Date]{
inline given dateConv: JsonConverter[Date] = new JsonConverter[Date] {
extension (a: Date)
override def toJsonValue: Json = JsonValue(a.toString)
override def toJson: String = a.toString
Expand All @@ -163,10 +163,10 @@ object JsonConverter:
def fromJson(value: Any): Option[A] =
value match
case null => None
case _ => Some(JsonConverter[A].fromJson(value))
case _ => Some(JsonConverter[A].fromJson(value))
}

given mapConv: [A: JsonConverter] => JsonCreator => JsonConverter[Map[String, A]] {
given mapConv: [A: JsonConverter] => JsonCreator => JsonConverter[Map[String, A]] {
extension (m: Map[String, A])
override def toJsonValue: Json =
summon[JsonCreator].fromMap(m)
Expand All @@ -181,35 +181,37 @@ object JsonConverter:
case _ => Map.empty
}

given immutableMapConv: [A: JsonConverter] => JsonCreator => JsonConverter[immutable.Map[String, A]] = new JsonConverter[immutable.Map[String, A]] {
extension (m: immutable.Map[String, A])
def toJsonValue: Json =
summon[JsonCreator].fromMap(m)
given immutableMapConv: [A: JsonConverter] => JsonCreator => JsonConverter[immutable.Map[String, A]] =
new JsonConverter[immutable.Map[String, A]] {
extension (m: immutable.Map[String, A])
def toJsonValue: Json =
summon[JsonCreator].fromMap(m)

def toJson: String =
summon[JsonCreator].fromMap(m).stringify()
def toJson: String =
summon[JsonCreator].fromMap(m).stringify()

def fromJson(value: Any): Map[String, A] =
value match
case obj: JsonObject =>
immutable.Map.from(jsonObjectToMap(obj))
case _ => immutable.Map.empty
}
def fromJson(value: Any): Map[String, A] =
value match
case obj: JsonObject =>
immutable.Map.from(jsonObjectToMap(obj))
case _ => immutable.Map.empty
}

given arrayConv: [A : {ClassTag, JsonConverter}] => JsonCreator => JsonConverter[Array[A]] = new JsonConverter[Array[A]] {
extension (a: Array[A])
def toJsonValue: Json =
summon[JsonCreator].fromIterable(a)
given arrayConv: [A: {ClassTag, JsonConverter}] => JsonCreator => JsonConverter[Array[A]] =
new JsonConverter[Array[A]] {
extension (a: Array[A])
def toJsonValue: Json =
summon[JsonCreator].fromIterable(a)

def toJson: String =
summon[JsonCreator].fromIterable(a).stringify()
def toJson: String =
summon[JsonCreator].fromIterable(a).stringify()

def fromJson(value: Any): Array[A] =
value match
case arr: JsonArray =>
jsonArrayToCollection(arr, Array.newBuilder)
case _ => Array.empty
}
def fromJson(value: Any): Array[A] =
value match
case arr: JsonArray =>
jsonArrayToCollection(arr, Array.newBuilder)
case _ => Array.empty
}

given iterableConv: [A: JsonConverter] => JsonCreator => JsonConverter[Iterable[A]] = new JsonConverter[Iterable[A]] {
extension (a: Iterable[A])
Expand Down Expand Up @@ -241,35 +243,37 @@ object JsonConverter:
case _ => Seq.empty
}

given immutableSeqConv: [A: JsonConverter] => JsonCreator => JsonConverter[immutable.Seq[A]] = new JsonConverter[immutable.Seq[A]] {
extension (a: immutable.Seq[A])
def toJsonValue: Json =
summon[JsonCreator].fromIterable(a)
given immutableSeqConv: [A: JsonConverter] => JsonCreator => JsonConverter[immutable.Seq[A]] =
new JsonConverter[immutable.Seq[A]] {
extension (a: immutable.Seq[A])
def toJsonValue: Json =
summon[JsonCreator].fromIterable(a)

def toJson: String =
summon[JsonCreator].fromIterable(a).stringify()
def toJson: String =
summon[JsonCreator].fromIterable(a).stringify()

def fromJson(value: Any): immutable.Seq[A] =
value match
case arr: JsonArray =>
jsonArrayToCollection(arr, immutable.Seq.newBuilder)
case _ => Seq.empty
}
def fromJson(value: Any): immutable.Seq[A] =
value match
case arr: JsonArray =>
jsonArrayToCollection(arr, immutable.Seq.newBuilder)
case _ => Seq.empty
}

given setCodec: [A: JsonConverter] => JsonCreator => JsonConverter[mutable.Set[A]] = new JsonConverter[mutable.Set[A]] {
extension (a: mutable.Set[A])
def toJsonValue: Json =
summon[JsonCreator].fromIterable(a)
given setCodec: [A: JsonConverter] => JsonCreator => JsonConverter[mutable.Set[A]] =
new JsonConverter[mutable.Set[A]] {
extension (a: mutable.Set[A])
def toJsonValue: Json =
summon[JsonCreator].fromIterable(a)

def toJson: String =
summon[JsonCreator].fromIterable(a).stringify()
def toJson: String =
summon[JsonCreator].fromIterable(a).stringify()

def fromJson(value: Any): mutable.Set[A] =
value match
case arr: JsonArray =>
jsonArrayToCollection(arr, mutable.HashSet.newBuilder)
case _ => mutable.HashSet.empty
}
def fromJson(value: Any): mutable.Set[A] =
value match
case arr: JsonArray =>
jsonArrayToCollection(arr, mutable.HashSet.newBuilder)
case _ => mutable.HashSet.empty
}

given immutableSetCodec: [A: JsonConverter] => JsonCreator => JsonConverter[Set[A]] = new JsonConverter[Set[A]] {
extension (a: Set[A])
Expand Down Expand Up @@ -316,20 +320,21 @@ object JsonConverter:
case _ => Vector.empty
}

given bufferConv: [A: JsonConverter] => JsonCreator => JsonConverter[mutable.Buffer[A]] = new JsonConverter[mutable.Buffer[A]] {
extension (a: mutable.Buffer[A])
def toJsonValue: Json =
summon[JsonCreator].fromIterable(a)
given bufferConv: [A: JsonConverter] => JsonCreator => JsonConverter[mutable.Buffer[A]] =
new JsonConverter[mutable.Buffer[A]] {
extension (a: mutable.Buffer[A])
def toJsonValue: Json =
summon[JsonCreator].fromIterable(a)

def toJson: String =
summon[JsonCreator].fromIterable(a).stringify()
def toJson: String =
summon[JsonCreator].fromIterable(a).stringify()

def fromJson(value: Any): mutable.Buffer[A] =
value match
case arr: JsonArray =>
jsonArrayToCollection(arr, mutable.Buffer.newBuilder)
case _ => mutable.Buffer.empty
}
def fromJson(value: Any): mutable.Buffer[A] =
value match
case arr: JsonArray =>
jsonArrayToCollection(arr, mutable.Buffer.newBuilder)
case _ => mutable.Buffer.empty
}

private def jsonObjectToMap[A](obj: JsonObject)(using
nc: JsonConverter[A]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object annotations:
case NumStr
case BoolStr
case DateStr[T](pattern: String)(using
val dateConverter: JsonDateConverter
val dateConverter: JsonDateConverter
)
case Auto

Expand Down