Now, it's not exactly a leap of faith to extend that and rather than code the template we can define this in a json document. Now all we need to do it to pass the json document and the collection name as parameters saving a recompile for each and every test. Happy days.
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
{ | |
"_id" : "someGeneratedValue" , | |
"nameOne" : "valueOne" , | |
"nameTwo" : "valueTwo" , | |
"sub" : { | |
"subNameOne" : "subValueOne" , | |
"subNameTwo" : "subValueTwo"} , | |
"array" : [ | |
{ "arraySubNameOne" : "arraySubValueOne"} , | |
{ "arraySubNameTwo" : "arraySubValueTwo"} | |
] | |
} |
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
StringBuffer temp = new StringBuffer(); | |
Scanner scanner = new Scanner(new FileReader("pathToFile.json")); | |
while (scanner.hasNextLine()) { | |
temp.append(scanner.nextLine()); | |
} | |
DBObject test = (DBObject)JSON.parse(temp.toString()); |
No comments:
Post a Comment