Skip to content

Commit 2fb99fc

Browse files
authored
Merge pull request #359 from Ganddalf/fix-github-pages
Fix github pages render
2 parents 39adb8e + a1286c0 commit 2fb99fc

File tree

1 file changed

+24
-36
lines changed

1 file changed

+24
-36
lines changed

README.md

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ It's advantages:
1616
* Discriminator support for sum types derivation
1717

1818
Read more about library usage bellow:
19-
- [Scala 3](https://github.com/tethys-json/tethys?tab=readme-ov-file#scala-3)
20-
- [Scala 2](https://github.com/tethys-json/tethys?tab=readme-ov-file#scala-2)
19+
- [Scala 3](#scala-3)
20+
- [Scala 2](#scala-2)
2121

2222

2323
# Scala 3
@@ -36,7 +36,7 @@ libraryDependencies ++= Seq(
3636
tethys provides extension methods allowing you to read and write JSON
3737

3838
They look something like this:
39-
```scala 3
39+
```scala
4040
package tethys
4141

4242
extension [A](value: A)
@@ -74,7 +74,7 @@ You can create new instances for your types using:
7474
1. **contramap** on already existing writer
7575
2. **map** on already existing reader
7676

77-
```scala 3
77+
```scala
7878
import tethys.*
7979

8080
case class StringWrapper(value: String) extends AnyVal
@@ -90,7 +90,7 @@ given JsonReader[StringWrapper] =
9090

9191
To build JsonWriter for case class you can use `obj` method on its companion object.
9292

93-
```scala 3
93+
```scala
9494
import tethys.*
9595

9696
case class MobileSession(
@@ -104,26 +104,23 @@ object MobileSession:
104104
.addField("id")(_.id)
105105
.addField("deviceId")(_.deviceId)
106106
.addField("userId")(_.userId)
107-
108107
```
109108

110109
You can concat multiple **JsonObjectWriter**.
111110
Combining concatenation with derivation allows to create **JsonWriter** for sealed trait.
112111
To derive JsonWriter for sealed trait you need to have **JsonObjectWriter** instances for all subtypes in scope
113112

114-
```scala 3
115-
113+
```scala
116114
given JsonWriter[Session] =
117115
JsonWriter.obj[Session].addField("typ")(_.typ) ++ JsonObjectWriter.derived[Session]
118-
119116
```
120117

121118

122119
### JsonReader
123120

124121
To build JsonReader for case class you can use `builder` method on its companion object.
125122

126-
```scala 3
123+
```scala
127124
import tethys.*
128125

129126
case class MobileSession(
@@ -138,13 +135,11 @@ import tethys.*
138135
.addField[String]("deviceId")
139136
.addField[java.lang.UUID]("userId")
140137
.buildReader(MobileSession(_, _, _))
141-
142-
143138
```
144139

145140
To build JsonReader for sealed trait you can use `selectReader` after adding some field:
146141

147-
```scala 3
142+
```scala
148143
import tethys.*
149144

150145
object Session:
@@ -157,15 +152,13 @@ import tethys.*
157152
case "web" => webReader
158153
case "mobile" => mobileReader
159154
}
160-
161-
162155
```
163156

164157

165158
## Derivation
166159

167160
All examples consider you made this imports:
168-
```scala 3
161+
```scala
169162
import tethys.*
170163
import tethys.jackson.* // or tethys.jackson.pretty.* for pretty printing
171164
```
@@ -174,7 +167,7 @@ import tethys.jackson.* // or tethys.jackson.pretty.* for pretty printing
174167
### Basic enums
175168
1. **StringEnumJsonWriter** and **StringEnumJsonReader**
176169

177-
```scala 3
170+
```scala
178171
enum SessionType derives StringEnumJsonWriter, StringEnumJsonReader:
179172
case Mobile, Web
180173

@@ -188,7 +181,7 @@ session.asJson == json
188181
```
189182
2. **OrdinalEnumJsonWriter** and **OrdinalEnumJsonReader**
190183

191-
```scala 3
184+
```scala
192185
enum SessionType derives OrdinalEnumJsonWriter, OrdinalEnumJsonReader:
193186
case Mobile, Web
194187

@@ -203,7 +196,7 @@ session.asJson == json
203196

204197
### Case classes
205198

206-
```scala 3
199+
```scala
207200
case class Session(
208201
id: Long,
209202
userId: String
@@ -224,7 +217,7 @@ Discriminator for **JsonWriter** is optional.
224217
If you don't need readers/writers for subtypes, you can omit them,
225218
they will be derived recursively for your trait/enum.
226219

227-
```scala 3
220+
```scala
228221
import tethys.selector
229222

230223
sealed trait UserAccount(@selector val typ: String) derives JsonReader, JsonObjectWriter
@@ -257,21 +250,21 @@ account.asJson == json
257250
3. To configure **JsonWriter** use **WriterBuilder**
258251
4. Configuration can be provided:
259252
* **directly to derived method**
260-
```scala 3
253+
```scala
261254
given JsonWriter[UserAccount.Customer] =
262255
JsonObjectWriter.derived {
263256
WriterBuilder[UserAccount.Customer]
264257
}
265258
```
266259
* **as an inline given to derives**
267-
```scala 3
260+
```scala
268261
object Customer:
269262
inline given WriterBuilder[UserAccount.Customer] =
270263
WriterBuilder[UserAccount.Customer]
271264
```
272265
P.S. There are empty **WriterBuilder** in the examples to simplify demonstration of two approaches. You shouldn't use empty one
273266
5. **WriterBuilder** features
274-
```scala 3
267+
```scala
275268
case class Foo(a: Int, b: String, c: Any, d: Boolean, e: Double)
276269

277270
inline given WriterBuilder[Foo] =
@@ -297,7 +290,7 @@ inline given WriterBuilder[Foo] =
297290
}
298291
```
299292
6. **ReaderBuilder** features
300-
```scala 3
293+
```scala
301294

302295
inline given ReaderBuilder[Foo] =
303296
ReaderBuilder[Foo]
@@ -321,12 +314,12 @@ inline given ReaderBuilder[Foo] =
321314
### Configuration via **JsonConfiguration**
322315
1. To configure both **JsonWriter** and **JsonReader** you can use **JsonConfiguration**
323316
2. **JsonConfiguration** can be provided as an inline given to derives
324-
```scala 3
317+
```scala
325318
inline given JsonConfiguration = JsonConfiguration.default
326319
```
327320
3. **JsonConfiguration** will be applied recursively to all nested readers/writers
328321
* Product types
329-
```scala 3
322+
```scala
330323
import tethys.*
331324
import tethys.jackson.*
332325

@@ -341,10 +334,9 @@ inline given JsonConfiguration = JsonConfiguration.default
341334

342335
json.jsonAs[Outer] == Right(outer)
343336
outer.asJson == json
344-
345337
```
346338
* Sum types
347-
```scala 3
339+
```scala
348340
import tethys.*
349341
import tethys.jackson.*
350342

@@ -367,7 +359,7 @@ inline given JsonConfiguration = JsonConfiguration.default
367359
secondJson.jsonAs[Choice] == second
368360
```
369361
4. **WriterBuilder** and **ReaderBuilder** settings have higher priority than **JsonConfiguration** settings
370-
```scala 3
362+
```scala
371363
import tethys.*
372364
import tethys.jackson.*
373365

@@ -392,11 +384,9 @@ val json = """{"ID": 5, "PHONENUMBER": "+123"}"""
392384

393385
json.jsonAs[Customer] == Right(customer)
394386
customer.asJson == json
395-
396387
```
397388
5. **JsonConfiguration** features
398-
```scala 3
399-
389+
```scala
400390
inline given JsonConfiguration =
401391
JsonConfiguration
402392
// default config, entrypoint for configuration
@@ -420,7 +410,7 @@ so tethys can offer you **circe** and **json4s** AST support
420410
libraryDependencies += "com.tethys-json" %% "tethys-circe" % tethysVersion
421411
```
422412

423-
```scala 3
413+
```scala
424414
import tethys.*
425415
import tethys.jackson.*
426416
import tethys.circe.*
@@ -465,7 +455,6 @@ libraryDependencies += "com.tethys-json" %% "tethys-enumeratum" % tethysVersion
465455

466456
enumeratum module provides a bunch of mixins for your Enum classes.
467457
```scala
468-
469458
import enumeratum.{Enum, EnumEntry}
470459
import tethys.enumeratum.*
471460

@@ -482,7 +471,6 @@ case object Direction extends Enum[Direction]
482471

483472
val values = findValues
484473
}
485-
486474
```
487475

488476
### Migration notes
@@ -503,7 +491,7 @@ Scala 3 derivation API in **0.29.0** has a lot of deprecations and is not fully
503491
* select some field from your model
504492
* provide type to method and name of field as string parameter
505493

506-
```scala 3
494+
```scala
507495
ReaderBuilder[SimpleType]
508496
.extract(_.i).from(_.d).and[Double]("e")((d, e) => (d + e).toInt)
509497
```

0 commit comments

Comments
 (0)