1
1
package org .elasticmq .rest .sqs
2
2
3
3
import org .elasticmq .{BinaryMessageAttribute , MessageAttribute , NumberMessageAttribute , StringMessageAttribute }
4
- import spray .json .{JsObject , JsString , JsValue , JsonReader , RootJsonFormat }
5
4
import spray .json .DefaultJsonProtocol ._
5
+ import spray .json .{JsObject , JsString , JsValue , JsonReader , RootJsonFormat }
6
6
7
7
trait MessageAttributesSupport {
8
8
9
+ private val SomeString = """ String\.?(.*)""" .r
10
+ private val SomeNumber = """ Number\.?(.*)""" .r
11
+ private val SomeBinary = """ Binary\.?(.*)""" .r
12
+
9
13
implicit val messageAttributeJsonFormat : RootJsonFormat [MessageAttribute ] = new RootJsonFormat [MessageAttribute ] {
10
14
11
15
override def write (obj : MessageAttribute ): JsValue = obj match {
@@ -25,11 +29,15 @@ trait MessageAttributesSupport {
25
29
26
30
val dataType = pickField[String ](" DataType" )
27
31
dataType match {
28
- case " Number" => NumberMessageAttribute (pickField[String ](" StringValue" ))
29
- case " String" => StringMessageAttribute (pickField[String ](" StringValue" ))
30
- case " Binary" => BinaryMessageAttribute (pickField[Array [Byte ]](" BinaryValue" ))
32
+ case SomeNumber (ct) => NumberMessageAttribute (pickField[String ](" StringValue" ), customType(ct))
33
+ case SomeString (ct) => StringMessageAttribute (pickField[String ](" StringValue" ), customType(ct))
34
+ case SomeBinary (ct) => BinaryMessageAttribute (pickField[Array [Byte ]](" BinaryValue" ), customType(ct))
35
+ case _ =>
36
+ throw new Exception (" Currently only handles String, Number and Binary typed attributes" )
31
37
}
32
38
}
39
+
40
+ private def customType (appendix : String ) = if (appendix.isEmpty) None else Some (appendix)
33
41
}
34
42
35
43
}
0 commit comments