PageRenderTime 51ms CodeModel.GetById 14ms app.highlight 30ms RepoModel.GetById 2ms app.codeStats 0ms

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