Skip to content

Commit 76e4016

Browse files
Update index.md
1 parent 276af5c commit 76e4016

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

index.md

+37
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,43 @@ class ApiController @Inject()(couchbase: Couchbase)
147147
}
148148
```
149149

150+
## What if I want to use a JSON lib other than Play Json ?
151+
152+
you can easily do that, actually everything linked to Play Json is imported from
153+
154+
```scala
155+
import org.reactivecouchbase.rs.scaladsl.json._
156+
```
157+
158+
then you just have to reimplement a few things
159+
160+
```scala
161+
import akka.util.ByteString
162+
import com.couchbase.client.java.document.json.JsonObject
163+
import org.reactivecouchbase.rs.scaladsl.json.{JsonReads, JsonWrites, JsonSuccess, QueryParams}
164+
import foo.bar.jsonlib.{JsonNode, JsonObj}
165+
166+
val read: JsonReads[JsonNode] = JsonReads(bs => JsonSuccess(JsonNode.parse(bs.utf8String)))
167+
val write: JsonWrites[JsonNode] = JsonWrites(jsv => ByteString(JsonNode.stringify(jsv)))
168+
169+
implicit val defaultByteStringFormat: JsonFormat[JsonNode] = JsonFormat(read, write)
170+
171+
implicit val defaultByteStringConverter: CouchbaseJsonDocConverter[JsonNode] = new CouchbaseJsonDocConverter[JsonNode] {
172+
override def convert(ref: AnyRef): JsonNode = ...
173+
}
174+
175+
case class JsonObjQueryParams(query: JsonObj = ByteString.empty) extends QueryParams {
176+
override def isEmpty: Boolean = !query.hasValue
177+
override def toJsonObject: JsonObject = ...
178+
}
179+
```
180+
181+
You have a few examples at
182+
183+
* https://github.com/ReactiveCouchbase/reactivecouchbase-rs-core/blob/master/src/main/scala/org/reactivecouchbase/rs/scaladsl/json/package.scala
184+
* https://github.com/ReactiveCouchbase/reactivecouchbase-rs-core/blob/master/src/main/scala/org/reactivecouchbase/rs/scaladsl/json/bytestring.scala
185+
* https://github.com/ReactiveCouchbase/reactivecouchbase-rs-core/blob/master/src/main/scala/org/reactivecouchbase/rs/scaladsl/json/converter.scala#L21-L31
186+
150187
# Projects
151188

152189
The core of ReactiveCouchbase RS is available on Gihtub and depends on Play Json library and Akka Streams

0 commit comments

Comments
 (0)