Wednesday, May 8, 2013

Play 2.1.x Writes Troubles

SO, This week's assignment was to learn how to use Reads/Writes Combinators. I started off with the play documentation on the same( http://www.playframework.com/documentation/2.1.1/ScalaJsonCombinators ) ,I wrote the functions for reads and writes which is given below.
But what I actually need to do was make an implicit call to the Reads and Writes. So i rewrote my function and this is the modified code is:
This code gave me no explicit error, but when i ran the code the:


The error in this output was that it should show me the id, name, age and address. Not just the address.
After doing a lot of checking, I realized there was no error from the db or any other functions. The only error was somewhere in the detailsWrite(), and no matter what i did it only printed the last value from the json.

So, with a little help, this is what i learnt:
The detailsWrite() function was giving an error because of the 2- level path that i was using
( __ \ "user" \ "id" )

Once I changed that into a simple path, it worked perfectly.
So the final code is here:

And the correct output.



No comments:

Post a Comment