Skip to content

Commit ec37dda

Browse files
author
QuadStingray
committed
Add Char Conversion
1 parent 6f17935 commit ec37dda

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/main/scala/com/sfxcode/nosql/mongo/bson/BsonConverter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.sfxcode.nosql.mongo.bson
22

33
import java.math.BigInteger
4-
import java.time.{ LocalDate, LocalDateTime, ZoneId }
4+
import java.time.{LocalDate, LocalDateTime, ZoneId}
55
import java.util.Date
66

77
import org.mongodb.scala.Document
@@ -28,6 +28,7 @@ object BsonConverter {
2828
converterPlugin.toBson(v)
2929
case b: Boolean => BsonBoolean(b)
3030
case s: String => BsonString(s)
31+
case c: Char => BsonString(c.toString)
3132
case bytes: Array[Byte] => BsonBinary(bytes)
3233
case r: Regex => BsonRegularExpression(r)
3334
case d: Date => BsonDateTime(d)

src/test/scala/com/sfxcode/nosql/mongo/converter/BsonConverterSpec.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package com.sfxcode.nosql.mongo.converter
22

33
import com.sfxcode.nosql.mongo.bson.BsonConverter
4-
import org.mongodb.scala.bson._
4+
import org.mongodb.scala.bson.{ObjectId, _}
55
import org.specs2.mutable.Specification
6-
76
/**
87
* Created by tom on 22.01.17.
98
*/
@@ -27,6 +26,13 @@ class BsonConverterSpec extends Specification {
2726
BsonConverter.toBson(BigInt(10)) must be equalTo BsonInt64(10)
2827
BsonConverter.toBson(java.math.BigInteger.TEN) must be equalTo BsonInt64(10)
2928

29+
BsonConverter.toBson(Some(5)) must be equalTo BsonInt32(5)
30+
31+
BsonConverter.toBson(Some(new ObjectId("5b61455932ac3f0015ae2e7e"))) must be equalTo BsonObjectId("5b61455932ac3f0015ae2e7e")
32+
33+
BsonConverter.toBson(None) must be equalTo BsonNull()
34+
35+
BsonConverter.toBson('M') must be equalTo BsonString("M")
3036
}
3137

3238
"convert values from BSON" in {

0 commit comments

Comments
 (0)