/src/test/scala/couch/json/Beans.scala

http://scouchdb.googlecode.com/ · Scala · 176 lines · 132 code · 44 blank · 0 comment · 0 complexity · 65c85b34b210bdd3fbf3149d70aa0b27 MD5 · raw file

  1. package couch.json
  2. import scala.reflect._
  3. object TestBeans {
  4. @BeanInfo
  5. case class Shop(store: String, item: String, price: Number) {
  6. private [json] def this() = this(null, null, null)
  7. override def toString = "shop = " + store + " for item " + item + " @ " + price
  8. }
  9. @BeanInfo
  10. case class Contact(name: String,
  11. @JSONTypeHint(classOf[Address])
  12. addresses: Map[String, Address]) {
  13. private [json] def this() = this(null, null)
  14. override def toString = "name = " + name + " addresses = " + addresses.map(a => a._1 + ":" + a._2.toString).mkString(",")
  15. }
  16. @BeanInfo
  17. case class Address(street: String, city: String, zip: String) {
  18. private [json] def this() = this(null, null, null)
  19. override def toString = "address = " + street + "/" + city + "/" + zip
  20. }
  21. @BeanInfo
  22. case class AddressWithOptionalCity(street: String, city: Option[String], zip: String) {
  23. private [json] def this() = this(null, None, null)
  24. override def toString = "address = " + street + "/" +
  25. (city match {
  26. case None => ""
  27. case Some(c) => c
  28. }) + "/" + zip
  29. }
  30. @BeanInfo
  31. case class ContactWithOptionalAddr(name: String,
  32. @JSONTypeHint(classOf[Address])
  33. @OptionTypeHint(classOf[Map[_,_]])
  34. addresses: Option[Map[String, Address]]) {
  35. private [json] def this() = this(null, None)
  36. override def toString = "name = " + name + " " +
  37. (addresses match {
  38. case None => ""
  39. case Some(ad) => " addresses = " + ad.map(a => a._1 + ":" + a._2.toString).mkString(",")
  40. })
  41. }
  42. @BeanInfo
  43. case class Person(lastName: String,
  44. firstName: String,
  45. @JSONTypeHint(classOf[Address])
  46. addresses: List[Address]) {
  47. def this() = this(null, null, Nil)
  48. override def toString = "person = " + lastName + "/" + firstName + "/" + addresses
  49. }
  50. @BeanInfo
  51. case class Book(id: Number,
  52. title: String, @JSONProperty("ISBN") isbn: String) {
  53. def this() = this(0, null, null)
  54. override def toString = "id = " + id + " title = " + title + " isbn = " + isbn
  55. }
  56. @BeanInfo
  57. case class Author(lastName: String, firstName: String) {
  58. private [json] def this() = this(null, null)
  59. }
  60. @BeanInfo
  61. case class Book_1(title: String, author: Author) {
  62. private [json] def this() = this(null, null)
  63. }
  64. @BeanInfo
  65. case class Journal(id: Int,
  66. title: String,
  67. author: String,
  68. @JSONProperty {val ignore = true} issn: String) {
  69. }
  70. @BeanInfo
  71. case class Journal_1(id: Int,
  72. title: String,
  73. author: String,
  74. @JSONProperty {val ignoreIfNull = true} issn: String) {
  75. }
  76. @BeanInfo
  77. class Journal_2(i: Int, t: String, au: String, is: String) {
  78. val id = i
  79. val title = t
  80. val author = au
  81. @JSONProperty("ISSN") {val ignoreIfNull = true}
  82. val issn = is
  83. }
  84. @BeanInfo
  85. class Item_1(i: String, ps: Map[String, Number]) {
  86. val item = i
  87. val prices = ps
  88. def this() = this(null, null)
  89. }
  90. @BeanInfo
  91. class Item_2(i: String, ps: List[Number]) {
  92. val item = i
  93. val prices = ps
  94. def this() = this(null, null)
  95. }
  96. @BeanInfo
  97. case class Instrument(
  98. val id: Number,
  99. val name: String,
  100. @JSONProperty("TYPE"){val ignoreIfNull = false, val ignore = false}
  101. val typ: String) {
  102. private [json] def this() = this(null, null, null)
  103. override def toString = "id: " + id + " name: " + name + " type: " + typ
  104. }
  105. @BeanInfo
  106. case class Trade(
  107. val ref: String,
  108. @JSONProperty("Instrument"){val ignoreIfNull = false, val ignore = false}
  109. val ins: Instrument,
  110. val amount: Number) {
  111. private [json] def this() = this(null, null, null)
  112. override def toString = "ref: " + ref + " ins: " + ins + " amount: " + amount
  113. }
  114. @BeanInfo
  115. case class Salary(val basic: Number, val allowance: Number) {
  116. private [json] def this() = this(null, null)
  117. }
  118. @BeanInfo
  119. class Employee(
  120. val id: Number,
  121. val name: String,
  122. @JSONProperty("Previous Employer"){val ignoreIfNull = true, val ignore = false}
  123. val prevEmployer: String,
  124. @JSONProperty("Addresses")
  125. @JSONTypeHint(classOf[Address])
  126. val addresses: List[Address],
  127. @JSONProperty("Salary")
  128. val sal: Salary
  129. ) {
  130. private [json] def this() = this(null, null, null, Nil, null)
  131. }
  132. }