-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Integration with uPickle | ||
======================== | ||
|
||
Records can be converted to/from JSON by using [uPickle][]. | ||
|
||
[uPickle]: https://com-lihaoyi.github.io/upickle/ | ||
|
||
Installation | ||
------------ | ||
|
||
You need an additional module to use records integrated with [uPickle][]. | ||
|
||
```scala | ||
libraryDependencies ++= Seq( | ||
"com.github.tarao" %% "record4s-upickle" % "@VERSION@" | ||
), | ||
``` | ||
|
||
From / To JSON | ||
-------------- | ||
|
||
Importing `Record.readWriter` enables [uPickle][] to decode/encode records in the ordinary way. | ||
|
||
```scala mdoc:mline | ||
import com.github.tarao.record4s.% | ||
import com.github.tarao.record4s.upickle.Record.readWriter | ||
import upickle.default.{read, write} | ||
|
||
type Person = % { val name: String; val age: Int } | ||
|
||
val json = """{"name":"tarao","age":3}""" | ||
|
||
// Read from JSON | ||
val r = read[Person](json) | ||
|
||
// Write it back | ||
write(r) | ||
``` |