Created
May 2, 2014 02:31
-
-
Save benkolera/11466581 to your computer and use it in GitHub Desktop.
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
import org.joda.time.DateTime | |
import org.joda.time.format.DateTimeFormat | |
import argonaut._ | |
import Argonaut._ | |
object InvariantFunctorBug { | |
case class RecordMeta( | |
externalId:String, | |
recordType:String, | |
name:String, | |
lastUpdate:DateTime, | |
nextUpdate:DateTime | |
) | |
case class Customer( | |
id: Int, | |
json: CustomerJson | |
) | |
case class CustomerJson( | |
meta: RecordMeta, | |
alias: String | |
) | |
val dtf = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ") | |
implicit def DateTimeToJson: CodecJson[DateTime] = | |
CodecJson( | |
(d: DateTime) => jString(dtf.print(d)), | |
d => for { | |
dt <- d.as[String] | |
} yield DateTime.parse(dt) | |
) | |
implicit def recordMetaCodec = casecodec5( RecordMeta.apply _ , RecordMeta.unapply _ )( | |
"externalId", | |
"recordType", | |
"name", | |
"lastUpdate", | |
"nextUpdate" | |
) | |
implicit def CustomerJsonToJson: CodecJson[CustomerJson] = casecodec2( | |
CustomerJson.apply , CustomerJson.unapply | |
)( | |
"meta", | |
"alias" | |
) | |
def main( args:Array[String]): Unit = { | |
println( | |
CustomerJson( | |
RecordMeta("","","",new DateTime,new DateTime), | |
"" | |
).asJson.spaces2 | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment