Permalink
Browse files

Merge pull request #66 from alexandreagular/bug-fix-option-int-float

Bug fix on parsing Option[Int] and Option[Float]
  • Loading branch information...
2 parents a22615b + 349ac54 commit 57927060da9b89b4a109180e858cb96e60ea42c0 @rktoomey rktoomey committed Dec 13, 2012
View
6 salat-core/src/main/scala/com/novus/salat/transformers/inject/Injectors.scala
@@ -46,18 +46,12 @@ package object in extends Logging {
case TypeRefType(_, symbol, _) if isBigDecimal(symbol.path) =>
new Transformer(symbol.path, t)(ctx) with OptionInjector with BigDecimalInjector
- case TypeRefType(_, symbol, _) if isInt(symbol.path) =>
- new Transformer(symbol.path, t)(ctx) with OptionInjector with LongToInt
-
case TypeRefType(_, symbol, _) if isBigInt(symbol.path) =>
new Transformer(symbol.path, t)(ctx) with OptionInjector with BigIntInjector
case TypeRefType(_, symbol, _) if isChar(symbol.path) =>
new Transformer(symbol.path, t)(ctx) with OptionInjector with StringToChar
- case TypeRefType(_, symbol, _) if isFloat(symbol.path) =>
- new Transformer(symbol.path, t)(ctx) with OptionInjector with DoubleToFloat
-
case TypeRefType(_, symbol, _) if isJodaDateTime(symbol.path) =>
new Transformer(symbol.path, t)(ctx) with OptionInjector with DateToJodaDateTime
View
58 salat-core/src/test/scala/com/novus/salat/test/OptionSpec.scala
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2010 - 2012 Novus Partners, Inc. (http://www.novus.com)
+ *
+ * Module: salat-core
+ * Class: FloatSpec.scala
+ * Last modified: 2012-10-15 20:40:58 EDT
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project: http://github.com/novus/salat
+ * Wiki: http://github.com/novus/salat/wiki
+ * Mailing list: http://groups.google.com/group/scala-salat
+ * StackOverflow: http://stackoverflow.com/questions/tagged/salat
+ */
+package com.novus.salat.test
+
+import com.novus.salat._
+import com.novus.salat.test.global._
+import com.novus.salat.test.model._
+import com.mongodb.casbah.Imports._
+
+class OptionSpec extends SalatSpec {
+ "A grater" should {
+ "support Option[Int] and Option[float]" in {
+ val a = OptionSpecExample(timestamp = Some(1356048000000L), valueInt = Some(26), valueDouble = Some(1337.0), valueFloat = Some(31047.0f))
+ val dbo: MongoDBObject = grater[OptionSpecExample].asDBObject(a)
+ dbo must havePair("_typeHint" -> "com.novus.salat.test.model.OptionSpecExample")
+ dbo must havePair("timestamp" -> 1356048000000L)
+ dbo must havePair("valueInt" -> 26)
+ dbo must havePair("valueDouble" -> 1337.0)
+ dbo must havePair("valueFloat" -> 31047.0f)
+
+ val json = dbo.toString()
+ grater[OptionSpecExample].fromJSON(json) must_== a
+
+ }
+ "support option not there" in {
+ val a = OptionSpecExample(None, None)
+ val dbo: MongoDBObject = grater[OptionSpecExample].asDBObject(a)
+ dbo must havePair("_typeHint" -> "com.novus.salat.test.model.OptionSpecExample")
+
+ val json = dbo.toString()
+ grater[OptionSpecExample].fromJSON(json) must_== a
+ }
+
+ }
+}
+
View
1 salat-core/src/test/scala/com/novus/salat/test/model/TestModel.scala
@@ -176,6 +176,7 @@ case class Olive(awl: java.util.UUID)
case class Quentin(mire: Float)
case class LongSpecExample(timestamp: Long, value: Int)
+case class OptionSpecExample(timestamp: Option[Long] = None, valueInt: Option[Int] = None, valueDouble: Option[Double] = None, valueFloat: Option[Float] = None)
case class Rhoda(consumed: Option[String] = None)
case class Rhoda2(howHot: Option[BigDecimal] = None)

0 comments on commit 5792706

Please sign in to comment.