Skip to content

Commit 4ac382f

Browse files
committed
Add json to the default set of mapped types and make the map public
1 parent 6de580e commit 4ac382f

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
dist: trusty
12
language: scala
23

34
scala:
@@ -7,6 +8,9 @@ scala:
78
jdk:
89
- oraclejdk8
910

11+
addons:
12+
postgresql: "9.5"
13+
1014
services:
1115
- postgresql
1216

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ val baseSettings = Seq(
1414
"com.twitter" %% "finagle-core" % "6.42.0",
1515
"org.scalatest" %% "scalatest" % "3.0.2" % "test,it",
1616
"org.scalacheck" %% "scalacheck" % "1.13.5" % "test,it",
17-
"org.scalamock" %% "scalamock-scalatest-support" % "3.4.2" % "test,it"
17+
"org.scalamock" %% "scalamock-scalatest-support" % "3.4.2" % "test,it",
18+
"io.circe" %% "circe-testing" % "0.7.0" % "test,it"
1819
)
1920
)
2021

src/main/scala/com/twitter/finagle/postgres/PostgresClient.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ object PostgresClient {
8181

8282
case class TypeSpecifier(receiveFunction: String, typeName: String, elemOid: Long = 0)
8383

84-
private[finagle] val defaultTypes = Map(
84+
val defaultTypes = Map(
8585
Types.BOOL -> TypeSpecifier("boolrecv", "bool"),
8686
Types.BYTE_A -> TypeSpecifier("bytearecv", "bytea"),
8787
Types.CHAR -> TypeSpecifier("charrecv", "char"),
@@ -95,6 +95,7 @@ object PostgresClient {
9595
Types.TID -> TypeSpecifier("tidrecv", "tid"),
9696
Types.XID -> TypeSpecifier("xidrecv", "xid"),
9797
Types.CID -> TypeSpecifier("cidrecv", "cid"),
98+
Types.JSON -> TypeSpecifier("json_recv", "json"),
9899
Types.XML -> TypeSpecifier("xml_recv", "xml"),
99100
Types.POINT -> TypeSpecifier("point_recv", "point"),
100101
Types.L_SEG -> TypeSpecifier("lseg_recv", "lseg"),

src/main/scala/com/twitter/finagle/postgres/values/Types.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ object Types {
1717
val TID = 27
1818
val XID = 28
1919
val CID = 29
20+
val JSON = 114
2021
val XML = 142
2122
val POINT = 600
2223
val L_SEG = 601

src/test/scala/com/twitter/finagle/postgres/values/ValuesSpec.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import com.twitter.finagle.postgres.PostgresClient.TypeSpecifier
1111
import com.twitter.finagle.postgres.messages.{DataRow, Field}
1212
import com.twitter.util.Await
1313
import org.jboss.netty.buffer.ChannelBuffers
14-
import org.scalacheck.Arbitrary
14+
import org.scalacheck.{Arbitrary, Gen}
1515
import Arbitrary.arbitrary
1616
import org.scalatest.prop.GeneratorDrivenPropertyChecks
17+
import io.circe.testing.instances.arbitraryJson
1718

1819
class ValuesSpec extends Spec with GeneratorDrivenPropertyChecks {
1920

@@ -138,6 +139,16 @@ class ValuesSpec extends Spec with GeneratorDrivenPropertyChecks {
138139
)
139140
"parse uuids" in test(ValueDecoder.uuid, ValueEncoder.uuid)("uuid_send", "uuid")
140141
"parse dates" in test(ValueDecoder.localDate, ValueEncoder.date)("date_send", "date")
142+
"parse json" in test(ValueDecoder.string, ValueEncoder.string)("json_send", "json")(
143+
Arbitrary(
144+
Gen.oneOf(
145+
arbitraryJson.arbitrary.map(_.noSpaces),
146+
arbitraryJson.arbitrary.map(_.spaces4),
147+
arbitraryJson.arbitrary.map(_.spaces2)
148+
).map(_.replace("\u0000", "\\u0000"))
149+
),
150+
client
151+
)
141152
}
142153
}
143154
}

0 commit comments

Comments
 (0)