| | | |
| 1 | 1 | | import scala.reflect.BeanProperty |
| 2 | 2 | | case class DenormalizedRating (@BeanProperty var actLevStart: Int, @BeanProperty var actLevEnd: Int) { |
| 3 | 3 | | def this () = this (0, 0) // Default constructor for flexjson. |
| 4 | 4 | | def activityRating = actLevEnd - actLevStart |
| 5 | 5 | | } |
| 7 | 7 | | def cl = new flexjson.ClassLocator { |
| 8 | 8 | | val classLoader = Thread.currentThread.getContextClassLoader |
| 9 | 9 | | override def locate (map: java.util.Map[_,_], path: flexjson.Path): Class[_] = { |
| 10 | 10 | | if (map.containsKey ("actLevStart")) classOf[DenormalizedRating] |
| 11 | 11 | | else { |
| 12 | 12 | | val clazz = map.get ("class") // Flexjson class signature. |
| 13 | 13 | | if (clazz.isInstanceOf[String]) classLoader.loadClass (clazz.toString) |
| 14 | 14 | | else classOf[java.util.HashMap[_, _]] |
| 15 | 15 | | } |
| 16 | 16 | | } |
| 17 | 17 | | } |
| 19 | 19 | | (new flexjson.JSONDeserializer () .use (null, cl) .deserialize (""" |
| 20 | 20 | | {"foo1": "bar1", |
| 21 | 21 | | "foo2": {"actLevStart": 1, "actLevEnd": 2}, |
| 22 | 22 | | "foo3": {"someMapKey": "someMapValue"}} |
| 23 | 23 | | """)).toString |