This is a library for parsing php-serialized data to scala object.
For SBT, add the following to your build file.
libraryDependencies += "com.sandinh" %% "php-unserializer" % "1.0.3"
(This is my real usage)
I have a RESTful service implemented in scala (use Play Framework) that need integrate to an existing website (use XenForo) to check if user is logged in & send a validated captcha when call my service.
Captcha correct answers is stored (by XenForo) in a BLOB column in Mysql. The code below will validate if answer is correct:
val blob: Array[Byte] = getDataFromDB()
val result = PhpUnserializer.parse(blob)
assert(result.isInstanceOf[Map[_, _]], "parsed value must be Map")
val expectedAnswers = result.asInstanceOf[Map[String, _]]
expectedAnswers should contain value "cường ẩ ẵ ự:;\""
def validate(answer: String) = expectedAnswers.exists{
case (_, s: String) => answer.equalsIgnoreCase(s)
case _ => false
}
assert(validate("cƯỜnG Ẩ Ẵ Ự:;\""))
@see full test code in PhpUnserializerSpec.scala
We use Semantic Versioning, so changing in micro version is binary compatible.
- parse large int to Long instead of Double
- add more test
cross compile to scala 2.11 & 2.10
Improved exception handling.
Add PhpUnserializer#parse(Array[Byte])
First stable release
This software is licensed under the Apache 2 license: http://www.apache.org/licenses/LICENSE-2.0
Copyright 2013 Sân Đình (http://sandinh.com)