This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit object ProductItemFormat extends RootJsonFormat[ProductItem] { | |
// some fields are optional so we produce a list of options and | |
// then flatten it to only write the fields that were Some(..) | |
def write(item: ProductItem) = JsObject( | |
List( | |
Some("product_number" -> item.productNumber.toJson), | |
item.ean.map(ean ⇒ "ean" -> ean.toJson), | |
Some("title" -> item.title.toJson), | |
item.description.map(description ⇒ "description" -> description.toJson), | |
Some("price" -> item.price.toJson), |