-
Notifications
You must be signed in to change notification settings - Fork 7
Add sphere-mongo-3 and sphere-json-3 (the scala 3 version of similarly named modules) #651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 113 commits
ff4171a
6aab3f9
91424e0
04a2d75
bbabb8a
77787a9
33049ff
4cee24d
3a120ca
c888f4f
cf41666
4da664c
a8845d1
396417a
dbee359
02388ea
9298ec3
8ced215
eccd881
e4ccd28
244dd51
cccf067
e19d164
363d3e7
2f5d1eb
1eb13a2
e2b478a
aecda6e
67943d7
ba48367
1b85335
8f2d38e
991644c
722edac
425bc8d
e5dc7f4
0796166
76e0073
62a6b76
0294477
7bf1515
f4311e6
f2cbf08
185d1c7
7b84b3c
3a509a5
bd03551
a8490a8
5c8db69
52e5e05
4eb3676
830e497
ab83fdd
964f12e
d35e499
43438a2
f9f0ef5
e2cf5eb
e0a00e6
868050b
c6bf620
65573fa
d2bd471
214003f
1b46be7
d290d98
f1ff371
eed2c79
c553fc9
40ab176
d1f850d
7e7c87a
c43a36e
ac35627
563ddbe
e78e849
422c4d1
8c2342e
23c468f
86578b5
d96edd8
fe15e40
eb5e3ca
6db374a
9363968
54be0ab
c00b484
1756aad
c0c4599
2172bf6
1c81994
436f004
6beea22
42ed16c
fe78216
4cfe4b8
a2bbfac
c39a9d1
d7237a0
1fc8ed1
6471cc0
67c17a4
4bf30da
fed317f
d0e2bd1
24ad816
a15a634
06cea48
0738ba6
cb2af67
9e9cbc5
7227566
9b1a4ae
a2d6c2d
9c586f5
da336cf
89c4fe6
b8e86b6
e08cd68
0491618
f8ea6ca
0338731
da44d9a
6c12f67
9e6a6eb
5304270
a13cd6f
0b585cd
941fe88
da63668
e479bdf
de01add
37765be
2b04357
cd8b331
d5ea170
e903fd4
54cb965
ef94c44
e33816a
5583c76
415cc9d
e60304b
84c3974
687c752
e6254cc
2cea052
17d506e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the benchmarks cannot run on scala 3? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scala 3 compilation was disabled before on the benchmarks module. I tried to compile while doing #664 but it uses |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.sphere.json | ||
|
||
import org.json4s.JsonAST._ | ||
|
||
import scala.annotation.implicitNotFound | ||
|
||
/** Type class for types that can be read from JSON. */ | ||
@implicitNotFound("Could not find an instance of FromJSON for ${A}") | ||
trait FromJSON[@specialized A] extends Serializable { | ||
def read(jval: JValue): JValidation[A] | ||
final protected def fail(msg: String) = jsonParseError(msg) | ||
|
||
/** needed JSON fields - ignored if empty */ | ||
val fields: Set[String] = FromJSON.emptyFieldsSet | ||
} | ||
|
||
object FromJSON extends FromJSONInstances with FromJSONCatsInstances { | ||
|
||
private[FromJSON] val emptyFieldsSet: Set[String] = Set.empty | ||
|
||
@inline def apply[A](implicit instance: FromJSON[A]): FromJSON[A] = instance | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.sphere.json | ||
|
||
import scala.annotation.implicitNotFound | ||
import java.time | ||
import org.json4s.JsonAST.JValue | ||
|
||
/** Type class for types that can be written to JSON. */ | ||
@implicitNotFound("Could not find an instance of ToJSON for ${A}") | ||
trait ToJSON[@specialized A] extends Serializable { | ||
def write(value: A): JValue | ||
} | ||
|
||
class JSONWriteException(msg: String) extends JSONException(msg) | ||
|
||
object ToJSON extends ToJSONInstances with ToJSONCatsInstances { | ||
|
||
@inline def apply[A](implicit instance: ToJSON[A]): ToJSON[A] = instance | ||
|
||
/** construct an instance from a function | ||
*/ | ||
def instance[T](toJson: T => JValue): ToJSON[T] = new ToJSON[T] { | ||
override def write(value: T): JValue = toJson(value) | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.sphere.json | ||
|
||
import io.sphere.json.JValidation | ||
import org.json4s.JsonAST.JValue | ||
|
||
/** Type class for types that can be read from JSON. */ | ||
trait FromJSON[A] extends Serializable { | ||
def read(jval: JValue): JValidation[A] | ||
final protected def fail(msg: String) = jsonParseError(msg) | ||
|
||
/** needed JSON fields - ignored if empty */ | ||
val fields: Set[String] = FromJSON.emptyFieldsSet | ||
} | ||
|
||
object FromJSON extends FromJSONInstances with FromJSONCatsInstances with generic.DeriveFromJSON { | ||
val emptyFieldsSet: Set[String] = Set.empty | ||
|
||
inline def apply[A](using instance: FromJSON[A]): FromJSON[A] = instance | ||
|
||
def instance[A]( | ||
readFn: JValue => JValidation[A], | ||
fieldSet: Set[String] = emptyFieldsSet): FromJSON[A] = new { | ||
|
||
override def read(jval: JValue): JValidation[A] = readFn(jval) | ||
override val fields: Set[String] = fieldSet | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.sphere.json | ||
|
||
import cats.implicits.* | ||
import org.json4s.JsonAST.JValue | ||
|
||
import scala.deriving.Mirror | ||
|
||
trait JSON[A] extends FromJSON[A] with ToJSON[A] | ||
|
||
inline def deriveJSON[A](using Mirror.Of[A]): JSON[A] = JSON.derived | ||
|
||
object JSON extends JSONCatsInstances { | ||
inline def apply[A: JSON]: JSON[A] = summon[JSON[A]] | ||
inline given derived[A](using fromJSON: FromJSON[A], toJSON: ToJSON[A]): JSON[A] = instance | ||
|
||
def instance[A]( | ||
readFn: JValue => JValidation[A], | ||
writeFn: A => JValue, | ||
fieldSet: Set[String] = FromJSON.emptyFieldsSet): JSON[A] = new { | ||
|
||
override def read(jval: JValue): JValidation[A] = readFn(jval) | ||
override def write(value: A): JValue = writeFn(value) | ||
override val fields: Set[String] = fieldSet | ||
} | ||
|
||
private def instance[A](using fromJSON: FromJSON[A], toJSON: ToJSON[A]): JSON[A] = | ||
new JSON[A] { | ||
override def read(jval: JValue): JValidation[A] = fromJSON.read(jval) | ||
|
||
override def write(value: A): JValue = toJSON.write(value) | ||
|
||
override val fields: Set[String] = fromJSON.fields | ||
} | ||
} | ||
|
||
class JSONException(msg: String) extends RuntimeException(msg) | ||
|
||
sealed abstract class JSONError | ||
case class JSONFieldError(path: List[String], message: String) extends JSONError { | ||
override def toString = path.mkString(" -> ") + ": " + message | ||
} | ||
case class JSONParseError(message: String) extends JSONError { | ||
override def toString = message | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.sphere.json | ||
|
||
import org.json4s.JsonAST.JValue | ||
|
||
import java.time | ||
import java.util.{Currency, Locale, UUID} | ||
|
||
/** Type class for types that can be written to JSON. */ | ||
trait ToJSON[A] extends Serializable { | ||
def write(value: A): JValue | ||
} | ||
|
||
class JSONWriteException(msg: String) extends JSONException(msg) | ||
|
||
object ToJSON extends ToJSONInstances with ToJSONCatsInstances with generic.DeriveToJSON { | ||
inline def apply[A](implicit instance: ToJSON[A]): ToJSON[A] = instance | ||
inline def apply[A: JSON]: ToJSON[A] = summon[ToJSON[A]] | ||
|
||
/** construct an instance from a function | ||
*/ | ||
def instance[T](toJson: T => JValue): ToJSON[T] = new ToJSON[T] { | ||
override def write(value: T): JValue = toJson(value) | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.