Last active
August 29, 2015 14:21
-
-
Save chuwy/5cddcdc089dcd1e3f0ca 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 java.io.{File, PrintWriter} | |
import org.json4s.jackson.JsonMethods._ | |
def printToFile(f: File)(op: PrintWriter => Unit) { | |
val p = new java.io.PrintWriter(f) | |
try { op(p) } finally { p.close() } | |
} | |
object jsonGen extends JsonGen | |
val innerShape = Map( | |
"inner_text" -> jsonGen.arbitraryJString | |
) | |
def generateShape = { | |
val innerJson = jsonGen.generateJsonWithKeys(innerShape) | |
Map( | |
"id" -> jsonGen.arbitraryJBool, | |
"created_at" -> jsonGen.arbitraryJIsoDate, | |
"is_new" -> jsonGen.arbitraryJBool, | |
"in" -> innerJson | |
) | |
} | |
for (i <- 1 to 5) { | |
val json = jsonGen.generateJsonWithKeys(generateShape) | |
val fileNameTemple = s"int_test_json_${i}.json" | |
json.sample match { | |
case Some(newJson) => printToFile(new File(fileNameTemple)) { f => | |
val rendered = pretty(render(newJson)) | |
f.print(rendered) | |
} | |
case _ => | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment