Created
August 17, 2011 16:50
-
-
Save jonifreeman/1151994 to your computer and use it in GitHub Desktop.
JsonDSL vs. JsonAST
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
("lotto" -> | |
("lotto-id" -> lotto.id) ~ | |
("winning-numbers" -> lotto.winningNumbers) ~ | |
("winners" -> | |
lotto.winners.map { w => | |
(("winner-id" -> w.id) ~ | |
("numbers" -> w.numbers))})) | |
// vs. | |
JObject(List( | |
JField("lotto", JObject(List( | |
JField("lotto-id", lotto.id), | |
JField("winning-numbers", lotto.winningNumbers), | |
JField("winners", | |
lotto.winners.map { w => | |
JObject(List( | |
JField("winner-id", w.id), | |
JField("numbers", w.numbers)))})))))) | |
/* Both generates: | |
{ | |
"lotto":{ | |
"lotto-id":5, | |
"winning-numbers":[2,45,34,23,7,5,3], | |
"winners":[{ | |
"winner-id":23, | |
"numbers":[2,45,34,23,3,5] | |
},{ | |
"winner-id":54, | |
"numbers":[52,3,12,11,18,22] | |
}] | |
} | |
} | |
*/ |
I'd prefer that too :) No way to make it work in Scala though.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd prefer the third one below :) Would it be possible to make such an DSL in scala?