[Lift] Re: Parcing Json

2010-01-14 Thread Randinn
Ah, I didn't know I was missing that. Right, I'll go back to chapter 6
in the book and see how to accomplish that, thank you for the info.

On Jan 15, 9:43 am, David Pollak 
wrote:
> On Thu, Jan 14, 2010 at 2:37 PM, Randinn  wrote:
> >http://paste.pocoo.org/show/165532/
>
> You have to write code that will copy each of the fields from the case class
> to the mapper object.
>
>
>
>
>
> > On Jan 15, 9:29 am, David Pollak 
> > wrote:
> > > On Thu, Jan 14, 2010 at 2:26 PM, Randinn  wrote:
> > > > Thank you both for your explanations it seems assigning val
> > > > Observation to Observe is a bad idea, what should I do to get the
> > > > parced information to the Observation map?
>
> > > What does your Observation class look like?
>
> > > > On Jan 15, 8:42 am, Ross Mellgren  wrote:
> > > > > Isn't it that the val Observation is being assigned to the (compiler
> > > > synthesized) Observe singleton object? In either case, no save method.
>
> > > > > -Ross
>
> > > > > On Jan 14, 2010, at 4:41 PM, David Pollak wrote:
>
> > > > > > On Thu, Jan 14, 2010 at 1:37 PM, Randinn 
> > wrote:
> > > > > > Well here is the latest iteration of the code:
>
> > > > > >http://paste.pocoo.org/show/165511/
>
> > > > > > but I'm getting this error
>
> > > > > > Compiling 11 source files to C:\Users\Randin\Documents\Development
> > > > > > \weather\target\classes at 1263504637934
> > > > > > [ERROR]weather/snippet/HelloWorld.scala:32: error: value save is
> > not a
> > > > > > member of object HelloWorld.this.Observe
> > > > > >  Observation.save
>
> > > > > > The Observation method is returning an instance of the Observe case
> > > > class.  This class has no "save" method on it, thus the error.
>
> > > > > >              ^
> > > > > > [ERROR]one error found
>
> > > > > > I went to 2.0-M1 and did a clean install. I assume save might be
> > the
> > > > > > answer, how close am I?
>
> > > > > > On Jan 4, 1:00 am, Joni Freeman  wrote:
> > > > > > > Google Groups does not shine in formatting code snippets. Here's
> > > > nicer
> > > > > > > version:
>
> > > > > > >http://paste.pocoo.org/show/161578/
>
> > > > > > > Cheers Joni
>
> > > > > > > On 3 tammi, 12:20, Joni Freeman  wrote:
>
> > > > > > > > Hi,
>
> > > > > > > > That's almost correct. I did following changes after looking
> > into
> > > > JSON
> > > > > > > > content.
>
> > > > > > > > 1. 'notice' and 'header' are JSON arrays just like 'data'.
> > > > Therefore:
> > > > > > > > case class Observation(notice: List[Notice], header:
> > List[Header],
> > > > > > > > data: List[Data])
>
> > > > > > > > 2. There's optional data in JSON (some datapoints are nulls and
> > > > Scala
> > > > > > > > Int or Double can't take null values). This can be fixed by
> > > > extracting
> > > > > > > > into Option.
>
> > > > > > > > 3. The extracted Observation is in JSON field 'observations'.
> > > > > > > > Therefore:
> > > > > > > > (json \ "observations").extract[Observation]
>
> > > > > > > > Your error stack trace suggests that you have an old version of
> > > > lift-
> > > > > > > > json. Please upgrade to M8, there was a critical bug in case
> > class
> > > > > > > > extraction in older versions.
>
> > > > > > > > Full example which works for me:
>
> > > > > > > >   implicit val formats = net.liftweb.json.DefaultFormats
> > > > > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > > > > disclaimer_url: String)
> > > > > > > >   case class Header(refresh_message: String, ID: String,
> > main_ID:
> > > > > > > > String, name: String, state_time_zone: String, time_zone:
> > String,
> > > > > > > > product_name: String, state: String)
> > > > > > > >   case class Data(sort_order: Int, wmo: Int, history_product:
> > > > String,
> > > > > > > > local_date_time: String,
> > > > > > > >                   local_date_time_full: String, air_temp:
> > Option
> > > > > > > > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> > > > > > > >                   rel_hum: Option[Int], delta_t:
> > Option[Double],
> > > > > > > > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > > > > > > > [Double],
> > > > > > > >                   wind_spd_kmh: Option[Double], press:
> > > > Option[Double],
> > > > > > > > rain_trace: String)
>
> > > > > > > >   case class Observation(notice: List[Notice], header:
> > > > List[Header],
> > > > > > > > data: List[Data])
>
> > > > > > > >   (json \ "observations").extract[Observation]
>
> > > > > > > > Cheers Joni
>
> > > > > > > > On 3 tammi, 09:17, Randinn  wrote:
>
> > > > > > > > > I'm having a bit of trouble with Lift Json parcing, I know
> > I'm
> > > > not
> > > > > > > > > doing it correctly but looking at the examples I cannot
> > figure
> > > > out
> > > > > > > > > what, anyway, here is the code in question. If someone
> > could
> > > > point
> > > > > > > > > me in the right direction that would be great, thanks in
> > advance.
>
> > > > > > > > > class HelloWorld {
> > > > > > > > >   def howdy = Welcome 

Re: [Lift] Re: Parcing Json

2010-01-14 Thread David Pollak
On Thu, Jan 14, 2010 at 2:37 PM, Randinn  wrote:

> http://paste.pocoo.org/show/165532/
>

You have to write code that will copy each of the fields from the case class
to the mapper object.


>
> On Jan 15, 9:29 am, David Pollak 
> wrote:
> > On Thu, Jan 14, 2010 at 2:26 PM, Randinn  wrote:
> > > Thank you both for your explanations it seems assigning val
> > > Observation to Observe is a bad idea, what should I do to get the
> > > parced information to the Observation map?
> >
> > What does your Observation class look like?
> >
> >
> >
> >
> >
> > > On Jan 15, 8:42 am, Ross Mellgren  wrote:
> > > > Isn't it that the val Observation is being assigned to the (compiler
> > > synthesized) Observe singleton object? In either case, no save method.
> >
> > > > -Ross
> >
> > > > On Jan 14, 2010, at 4:41 PM, David Pollak wrote:
> >
> > > > > On Thu, Jan 14, 2010 at 1:37 PM, Randinn 
> wrote:
> > > > > Well here is the latest iteration of the code:
> >
> > > > >http://paste.pocoo.org/show/165511/
> >
> > > > > but I'm getting this error
> >
> > > > > Compiling 11 source files to C:\Users\Randin\Documents\Development
> > > > > \weather\target\classes at 1263504637934
> > > > > [ERROR]weather/snippet/HelloWorld.scala:32: error: value save is
> not a
> > > > > member of object HelloWorld.this.Observe
> > > > >  Observation.save
> >
> > > > > The Observation method is returning an instance of the Observe case
> > > class.  This class has no "save" method on it, thus the error.
> >
> > > > >  ^
> > > > > [ERROR]one error found
> >
> > > > > I went to 2.0-M1 and did a clean install. I assume save might be
> the
> > > > > answer, how close am I?
> >
> > > > > On Jan 4, 1:00 am, Joni Freeman  wrote:
> > > > > > Google Groups does not shine in formatting code snippets. Here's
> > > nicer
> > > > > > version:
> >
> > > > > >http://paste.pocoo.org/show/161578/
> >
> > > > > > Cheers Joni
> >
> > > > > > On 3 tammi, 12:20, Joni Freeman  wrote:
> >
> > > > > > > Hi,
> >
> > > > > > > That's almost correct. I did following changes after looking
> into
> > > JSON
> > > > > > > content.
> >
> > > > > > > 1. 'notice' and 'header' are JSON arrays just like 'data'.
> > > Therefore:
> > > > > > > case class Observation(notice: List[Notice], header:
> List[Header],
> > > > > > > data: List[Data])
> >
> > > > > > > 2. There's optional data in JSON (some datapoints are nulls and
> > > Scala
> > > > > > > Int or Double can't take null values). This can be fixed by
> > > extracting
> > > > > > > into Option.
> >
> > > > > > > 3. The extracted Observation is in JSON field 'observations'.
> > > > > > > Therefore:
> > > > > > > (json \ "observations").extract[Observation]
> >
> > > > > > > Your error stack trace suggests that you have an old version of
> > > lift-
> > > > > > > json. Please upgrade to M8, there was a critical bug in case
> class
> > > > > > > extraction in older versions.
> >
> > > > > > > Full example which works for me:
> >
> > > > > > >   implicit val formats = net.liftweb.json.DefaultFormats
> > > > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > > > disclaimer_url: String)
> > > > > > >   case class Header(refresh_message: String, ID: String,
> main_ID:
> > > > > > > String, name: String, state_time_zone: String, time_zone:
> String,
> > > > > > > product_name: String, state: String)
> > > > > > >   case class Data(sort_order: Int, wmo: Int, history_product:
> > > String,
> > > > > > > local_date_time: String,
> > > > > > >   local_date_time_full: String, air_temp:
> Option
> > > > > > > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> > > > > > >   rel_hum: Option[Int], delta_t:
> Option[Double],
> > > > > > > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > > > > > > [Double],
> > > > > > >   wind_spd_kmh: Option[Double], press:
> > > Option[Double],
> > > > > > > rain_trace: String)
> >
> > > > > > >   case class Observation(notice: List[Notice], header:
> > > List[Header],
> > > > > > > data: List[Data])
> >
> > > > > > >   (json \ "observations").extract[Observation]
> >
> > > > > > > Cheers Joni
> >
> > > > > > > On 3 tammi, 09:17, Randinn  wrote:
> >
> > > > > > > > I'm having a bit of trouble with Lift Json parcing, I know
> I'm
> > > not
> > > > > > > > doing it correctly but looking at the examples I cannot
> figure
> > > out
> > > > > > > > what, anyway, here is the code in question. If someone
> could
> > > point
> > > > > > > > me in the right direction that would be great, thanks in
> advance.
> >
> > > > > > > > class HelloWorld {
> > > > > > > >   def howdy = Welcome to hello-lift at {new
> > > > > > > > _root_.java.util.Date}
> > > > > > > > val http = new Http
> > > > > > > > val bos = new ByteArrayOutputStream
> > > > > > > > val myRequest = new Request("
> http://www.bom.gov.au/fwo/IDV60901/
> > > > > > > > IDV60901.94868.json")
> > > > > > > > val rawdata = http(myRequest >>> 

[Lift] Re: Parcing Json

2010-01-14 Thread Randinn
http://paste.pocoo.org/show/165532/

On Jan 15, 9:29 am, David Pollak 
wrote:
> On Thu, Jan 14, 2010 at 2:26 PM, Randinn  wrote:
> > Thank you both for your explanations it seems assigning val
> > Observation to Observe is a bad idea, what should I do to get the
> > parced information to the Observation map?
>
> What does your Observation class look like?
>
>
>
>
>
> > On Jan 15, 8:42 am, Ross Mellgren  wrote:
> > > Isn't it that the val Observation is being assigned to the (compiler
> > synthesized) Observe singleton object? In either case, no save method.
>
> > > -Ross
>
> > > On Jan 14, 2010, at 4:41 PM, David Pollak wrote:
>
> > > > On Thu, Jan 14, 2010 at 1:37 PM, Randinn  wrote:
> > > > Well here is the latest iteration of the code:
>
> > > >http://paste.pocoo.org/show/165511/
>
> > > > but I'm getting this error
>
> > > > Compiling 11 source files to C:\Users\Randin\Documents\Development
> > > > \weather\target\classes at 1263504637934
> > > > [ERROR]weather/snippet/HelloWorld.scala:32: error: value save is not a
> > > > member of object HelloWorld.this.Observe
> > > >  Observation.save
>
> > > > The Observation method is returning an instance of the Observe case
> > class.  This class has no "save" method on it, thus the error.
>
> > > >              ^
> > > > [ERROR]one error found
>
> > > > I went to 2.0-M1 and did a clean install. I assume save might be the
> > > > answer, how close am I?
>
> > > > On Jan 4, 1:00 am, Joni Freeman  wrote:
> > > > > Google Groups does not shine in formatting code snippets. Here's
> > nicer
> > > > > version:
>
> > > > >http://paste.pocoo.org/show/161578/
>
> > > > > Cheers Joni
>
> > > > > On 3 tammi, 12:20, Joni Freeman  wrote:
>
> > > > > > Hi,
>
> > > > > > That's almost correct. I did following changes after looking into
> > JSON
> > > > > > content.
>
> > > > > > 1. 'notice' and 'header' are JSON arrays just like 'data'.
> > Therefore:
> > > > > > case class Observation(notice: List[Notice], header: List[Header],
> > > > > > data: List[Data])
>
> > > > > > 2. There's optional data in JSON (some datapoints are nulls and
> > Scala
> > > > > > Int or Double can't take null values). This can be fixed by
> > extracting
> > > > > > into Option.
>
> > > > > > 3. The extracted Observation is in JSON field 'observations'.
> > > > > > Therefore:
> > > > > > (json \ "observations").extract[Observation]
>
> > > > > > Your error stack trace suggests that you have an old version of
> > lift-
> > > > > > json. Please upgrade to M8, there was a critical bug in case class
> > > > > > extraction in older versions.
>
> > > > > > Full example which works for me:
>
> > > > > >   implicit val formats = net.liftweb.json.DefaultFormats
> > > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > > disclaimer_url: String)
> > > > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > > > String, name: String, state_time_zone: String, time_zone: String,
> > > > > > product_name: String, state: String)
> > > > > >   case class Data(sort_order: Int, wmo: Int, history_product:
> > String,
> > > > > > local_date_time: String,
> > > > > >                   local_date_time_full: String, air_temp: Option
> > > > > > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> > > > > >                   rel_hum: Option[Int], delta_t: Option[Double],
> > > > > > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > > > > > [Double],
> > > > > >                   wind_spd_kmh: Option[Double], press:
> > Option[Double],
> > > > > > rain_trace: String)
>
> > > > > >   case class Observation(notice: List[Notice], header:
> > List[Header],
> > > > > > data: List[Data])
>
> > > > > >   (json \ "observations").extract[Observation]
>
> > > > > > Cheers Joni
>
> > > > > > On 3 tammi, 09:17, Randinn  wrote:
>
> > > > > > > I'm having a bit of trouble with Lift Json parcing, I know I'm
> > not
> > > > > > > doing it correctly but looking at the examples I cannot figure
> > out
> > > > > > > what, anyway, here is the code in question. If someone could
> > point
> > > > > > > me in the right direction that would be great, thanks in advance.
>
> > > > > > > class HelloWorld {
> > > > > > >   def howdy = Welcome to hello-lift at {new
> > > > > > > _root_.java.util.Date}
> > > > > > > val http = new Http
> > > > > > > val bos = new ByteArrayOutputStream
> > > > > > > val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> > > > > > > IDV60901.94868.json")
> > > > > > > val rawdata = http(myRequest >>> bos)
> > > > > > > val bs = bos.toString
> > > > > > > val db = :/("www.bom.gov.au")
>
> > > > > > > val json = parse(bs)
>
> > > > > > > implicit val formats = net.liftweb.json.DefaultFormats
> > > > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > > > disclaimer_url: String)
> > > > > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > > > > String, name: String, state_time_zone: 

Re: [Lift] Re: Parcing Json

2010-01-14 Thread David Pollak
On Thu, Jan 14, 2010 at 2:26 PM, Randinn  wrote:

> Thank you both for your explanations it seems assigning val
> Observation to Observe is a bad idea, what should I do to get the
> parced information to the Observation map?
>

What does your Observation class look like?


>
> On Jan 15, 8:42 am, Ross Mellgren  wrote:
> > Isn't it that the val Observation is being assigned to the (compiler
> synthesized) Observe singleton object? In either case, no save method.
> >
> > -Ross
> >
> > On Jan 14, 2010, at 4:41 PM, David Pollak wrote:
> >
> >
> >
> > > On Thu, Jan 14, 2010 at 1:37 PM, Randinn  wrote:
> > > Well here is the latest iteration of the code:
> >
> > >http://paste.pocoo.org/show/165511/
> >
> > > but I'm getting this error
> >
> > > Compiling 11 source files to C:\Users\Randin\Documents\Development
> > > \weather\target\classes at 1263504637934
> > > [ERROR]weather/snippet/HelloWorld.scala:32: error: value save is not a
> > > member of object HelloWorld.this.Observe
> > >  Observation.save
> >
> > > The Observation method is returning an instance of the Observe case
> class.  This class has no "save" method on it, thus the error.
> >
> > >  ^
> > > [ERROR]one error found
> >
> > > I went to 2.0-M1 and did a clean install. I assume save might be the
> > > answer, how close am I?
> >
> > > On Jan 4, 1:00 am, Joni Freeman  wrote:
> > > > Google Groups does not shine in formatting code snippets. Here's
> nicer
> > > > version:
> >
> > > >http://paste.pocoo.org/show/161578/
> >
> > > > Cheers Joni
> >
> > > > On 3 tammi, 12:20, Joni Freeman  wrote:
> >
> > > > > Hi,
> >
> > > > > That's almost correct. I did following changes after looking into
> JSON
> > > > > content.
> >
> > > > > 1. 'notice' and 'header' are JSON arrays just like 'data'.
> Therefore:
> > > > > case class Observation(notice: List[Notice], header: List[Header],
> > > > > data: List[Data])
> >
> > > > > 2. There's optional data in JSON (some datapoints are nulls and
> Scala
> > > > > Int or Double can't take null values). This can be fixed by
> extracting
> > > > > into Option.
> >
> > > > > 3. The extracted Observation is in JSON field 'observations'.
> > > > > Therefore:
> > > > > (json \ "observations").extract[Observation]
> >
> > > > > Your error stack trace suggests that you have an old version of
> lift-
> > > > > json. Please upgrade to M8, there was a critical bug in case class
> > > > > extraction in older versions.
> >
> > > > > Full example which works for me:
> >
> > > > >   implicit val formats = net.liftweb.json.DefaultFormats
> > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > disclaimer_url: String)
> > > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > > String, name: String, state_time_zone: String, time_zone: String,
> > > > > product_name: String, state: String)
> > > > >   case class Data(sort_order: Int, wmo: Int, history_product:
> String,
> > > > > local_date_time: String,
> > > > >   local_date_time_full: String, air_temp: Option
> > > > > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> > > > >   rel_hum: Option[Int], delta_t: Option[Double],
> > > > > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > > > > [Double],
> > > > >   wind_spd_kmh: Option[Double], press:
> Option[Double],
> > > > > rain_trace: String)
> >
> > > > >   case class Observation(notice: List[Notice], header:
> List[Header],
> > > > > data: List[Data])
> >
> > > > >   (json \ "observations").extract[Observation]
> >
> > > > > Cheers Joni
> >
> > > > > On 3 tammi, 09:17, Randinn  wrote:
> >
> > > > > > I'm having a bit of trouble with Lift Json parcing, I know I'm
> not
> > > > > > doing it correctly but looking at the examples I cannot figure
> out
> > > > > > what, anyway, here is the code in question. If someone could
> point
> > > > > > me in the right direction that would be great, thanks in advance.
> >
> > > > > > class HelloWorld {
> > > > > >   def howdy = Welcome to hello-lift at {new
> > > > > > _root_.java.util.Date}
> > > > > > val http = new Http
> > > > > > val bos = new ByteArrayOutputStream
> > > > > > val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> > > > > > IDV60901.94868.json")
> > > > > > val rawdata = http(myRequest >>> bos)
> > > > > > val bs = bos.toString
> > > > > > val db = :/("www.bom.gov.au")
> >
> > > > > > val json = parse(bs)
> >
> > > > > > implicit val formats = net.liftweb.json.DefaultFormats
> > > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > > disclaimer_url: String)
> > > > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > > > String, name: String, state_time_zone: String,
> > > > > > time_zone: String, product_name: String,
> state:
> > > > > > String)
> > > > > >   case class Data(sort_order: Int, wmo: Int, history_product:
> String,
> > > > > > local_da

[Lift] Re: Parcing Json

2010-01-14 Thread Randinn
Thank you both for your explanations it seems assigning val
Observation to Observe is a bad idea, what should I do to get the
parced information to the Observation map?

On Jan 15, 8:42 am, Ross Mellgren  wrote:
> Isn't it that the val Observation is being assigned to the (compiler 
> synthesized) Observe singleton object? In either case, no save method.
>
> -Ross
>
> On Jan 14, 2010, at 4:41 PM, David Pollak wrote:
>
>
>
> > On Thu, Jan 14, 2010 at 1:37 PM, Randinn  wrote:
> > Well here is the latest iteration of the code:
>
> >http://paste.pocoo.org/show/165511/
>
> > but I'm getting this error
>
> > Compiling 11 source files to C:\Users\Randin\Documents\Development
> > \weather\target\classes at 1263504637934
> > [ERROR]weather/snippet/HelloWorld.scala:32: error: value save is not a
> > member of object HelloWorld.this.Observe
> >  Observation.save
>
> > The Observation method is returning an instance of the Observe case class.  
> > This class has no "save" method on it, thus the error.
>
> >              ^
> > [ERROR]one error found
>
> > I went to 2.0-M1 and did a clean install. I assume save might be the
> > answer, how close am I?
>
> > On Jan 4, 1:00 am, Joni Freeman  wrote:
> > > Google Groups does not shine in formatting code snippets. Here's nicer
> > > version:
>
> > >http://paste.pocoo.org/show/161578/
>
> > > Cheers Joni
>
> > > On 3 tammi, 12:20, Joni Freeman  wrote:
>
> > > > Hi,
>
> > > > That's almost correct. I did following changes after looking into JSON
> > > > content.
>
> > > > 1. 'notice' and 'header' are JSON arrays just like 'data'. Therefore:
> > > > case class Observation(notice: List[Notice], header: List[Header],
> > > > data: List[Data])
>
> > > > 2. There's optional data in JSON (some datapoints are nulls and Scala
> > > > Int or Double can't take null values). This can be fixed by extracting
> > > > into Option.
>
> > > > 3. The extracted Observation is in JSON field 'observations'.
> > > > Therefore:
> > > > (json \ "observations").extract[Observation]
>
> > > > Your error stack trace suggests that you have an old version of lift-
> > > > json. Please upgrade to M8, there was a critical bug in case class
> > > > extraction in older versions.
>
> > > > Full example which works for me:
>
> > > >   implicit val formats = net.liftweb.json.DefaultFormats
> > > >   case class Notice(copyright: String, copyright_url: String,
> > > > disclaimer_url: String)
> > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > String, name: String, state_time_zone: String, time_zone: String,
> > > > product_name: String, state: String)
> > > >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > > > local_date_time: String,
> > > >                   local_date_time_full: String, air_temp: Option
> > > > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> > > >                   rel_hum: Option[Int], delta_t: Option[Double],
> > > > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > > > [Double],
> > > >                   wind_spd_kmh: Option[Double], press: Option[Double],
> > > > rain_trace: String)
>
> > > >   case class Observation(notice: List[Notice], header: List[Header],
> > > > data: List[Data])
>
> > > >   (json \ "observations").extract[Observation]
>
> > > > Cheers Joni
>
> > > > On 3 tammi, 09:17, Randinn  wrote:
>
> > > > > I'm having a bit of trouble with Lift Json parcing, I know I'm not
> > > > > doing it correctly but looking at the examples I cannot figure out
> > > > > what, anyway, here is the code in question. If someone could point
> > > > > me in the right direction that would be great, thanks in advance.
>
> > > > > class HelloWorld {
> > > > >   def howdy = Welcome to hello-lift at {new
> > > > > _root_.java.util.Date}
> > > > > val http = new Http
> > > > > val bos = new ByteArrayOutputStream
> > > > > val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> > > > > IDV60901.94868.json")
> > > > > val rawdata = http(myRequest >>> bos)
> > > > > val bs = bos.toString
> > > > > val db = :/("www.bom.gov.au")
>
> > > > > val json = parse(bs)
>
> > > > > implicit val formats = net.liftweb.json.DefaultFormats
> > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > disclaimer_url: String)
> > > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > > String, name: String, state_time_zone: String,
> > > > >                     time_zone: String, product_name: String, state:
> > > > > String)
> > > > >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > > > > local_date_time: String,
> > > > >                   local_date_time_full: Int, air_temp: Double, dewpt:
> > > > > Double, apparent_t: Double,
> > > > >                   rel_hum: Double, delta_t: Double, wind_dir: Double,
> > > > > wind_spd_kt: Double, gust_kt: Double,
> > > > >                   wind_spd_kmh: Double, press: Double, rain_trace:
> > > > > Double)
> 

Re: [Lift] Re: Parcing Json

2010-01-14 Thread Ross Mellgren
Isn't it that the val Observation is being assigned to the (compiler 
synthesized) Observe singleton object? In either case, no save method.

-Ross

On Jan 14, 2010, at 4:41 PM, David Pollak wrote:

> 
> 
> On Thu, Jan 14, 2010 at 1:37 PM, Randinn  wrote:
> Well here is the latest iteration of the code:
> 
> http://paste.pocoo.org/show/165511/
> 
> but I'm getting this error
> 
> Compiling 11 source files to C:\Users\Randin\Documents\Development
> \weather\target\classes at 1263504637934
> [ERROR]weather/snippet/HelloWorld.scala:32: error: value save is not a
> member of object HelloWorld.this.Observe
>  Observation.save
> 
> The Observation method is returning an instance of the Observe case class.  
> This class has no "save" method on it, thus the error.
>  
>  ^
> [ERROR]one error found
> 
> I went to 2.0-M1 and did a clean install. I assume save might be the
> answer, how close am I?
> 
> On Jan 4, 1:00 am, Joni Freeman  wrote:
> > Google Groups does not shine in formatting code snippets. Here's nicer
> > version:
> >
> > http://paste.pocoo.org/show/161578/
> >
> > Cheers Joni
> >
> > On 3 tammi, 12:20, Joni Freeman  wrote:
> >
> > > Hi,
> >
> > > That's almost correct. I did following changes after looking into JSON
> > > content.
> >
> > > 1. 'notice' and 'header' are JSON arrays just like 'data'. Therefore:
> > > case class Observation(notice: List[Notice], header: List[Header],
> > > data: List[Data])
> >
> > > 2. There's optional data in JSON (some datapoints are nulls and Scala
> > > Int or Double can't take null values). This can be fixed by extracting
> > > into Option.
> >
> > > 3. The extracted Observation is in JSON field 'observations'.
> > > Therefore:
> > > (json \ "observations").extract[Observation]
> >
> > > Your error stack trace suggests that you have an old version of lift-
> > > json. Please upgrade to M8, there was a critical bug in case class
> > > extraction in older versions.
> >
> > > Full example which works for me:
> >
> > >   implicit val formats = net.liftweb.json.DefaultFormats
> > >   case class Notice(copyright: String, copyright_url: String,
> > > disclaimer_url: String)
> > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > String, name: String, state_time_zone: String, time_zone: String,
> > > product_name: String, state: String)
> > >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > > local_date_time: String,
> > >   local_date_time_full: String, air_temp: Option
> > > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> > >   rel_hum: Option[Int], delta_t: Option[Double],
> > > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > > [Double],
> > >   wind_spd_kmh: Option[Double], press: Option[Double],
> > > rain_trace: String)
> >
> > >   case class Observation(notice: List[Notice], header: List[Header],
> > > data: List[Data])
> >
> > >   (json \ "observations").extract[Observation]
> >
> > > Cheers Joni
> >
> > > On 3 tammi, 09:17, Randinn  wrote:
> >
> > > > I'm having a bit of trouble with Lift Json parcing, I know I'm not
> > > > doing it correctly but looking at the examples I cannot figure out
> > > > what, anyway, here is the code in question. If someone could point
> > > > me in the right direction that would be great, thanks in advance.
> >
> > > > class HelloWorld {
> > > >   def howdy = Welcome to hello-lift at {new
> > > > _root_.java.util.Date}
> > > > val http = new Http
> > > > val bos = new ByteArrayOutputStream
> > > > val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> > > > IDV60901.94868.json")
> > > > val rawdata = http(myRequest >>> bos)
> > > > val bs = bos.toString
> > > > val db = :/("www.bom.gov.au")
> >
> > > > val json = parse(bs)
> >
> > > > implicit val formats = net.liftweb.json.DefaultFormats
> > > >   case class Notice(copyright: String, copyright_url: String,
> > > > disclaimer_url: String)
> > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > String, name: String, state_time_zone: String,
> > > > time_zone: String, product_name: String, state:
> > > > String)
> > > >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > > > local_date_time: String,
> > > >   local_date_time_full: Int, air_temp: Double, dewpt:
> > > > Double, apparent_t: Double,
> > > >   rel_hum: Double, delta_t: Double, wind_dir: Double,
> > > > wind_spd_kt: Double, gust_kt: Double,
> > > >   wind_spd_kmh: Double, press: Double, rain_trace:
> > > > Double)
> > > >   case class Observation(notice: Notice, header: Header, data: List
> > > > [Data])
> > > > json.extract[Observation]
> >
> >
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "Lift" group.
> To post to this group, send email to lift...@googlegroups.com.
> To unsubscribe from this group, send email to 

Re: [Lift] Re: Parcing Json

2010-01-14 Thread David Pollak
On Thu, Jan 14, 2010 at 1:37 PM, Randinn  wrote:

> Well here is the latest iteration of the code:
>
> http://paste.pocoo.org/show/165511/
>
> but I'm getting this error
>
> Compiling 11 source files to C:\Users\Randin\Documents\Development
> \weather\target\classes at 1263504637934
> [ERROR]weather/snippet/HelloWorld.scala:32: error: value save is not a
> member of object HelloWorld.this.Observe
>  Observation.save
>

The Observation method is returning an instance of the Observe case class.
This class has no "save" method on it, thus the error.


>  ^
> [ERROR]one error found
>
> I went to 2.0-M1 and did a clean install. I assume save might be the
> answer, how close am I?
>
> On Jan 4, 1:00 am, Joni Freeman  wrote:
> > Google Groups does not shine in formatting code snippets. Here's nicer
> > version:
> >
> > http://paste.pocoo.org/show/161578/
> >
> > Cheers Joni
> >
> > On 3 tammi, 12:20, Joni Freeman  wrote:
> >
> > > Hi,
> >
> > > That's almost correct. I did following changes after looking into JSON
> > > content.
> >
> > > 1. 'notice' and 'header' are JSON arrays just like 'data'. Therefore:
> > > case class Observation(notice: List[Notice], header: List[Header],
> > > data: List[Data])
> >
> > > 2. There's optional data in JSON (some datapoints are nulls and Scala
> > > Int or Double can't take null values). This can be fixed by extracting
> > > into Option.
> >
> > > 3. The extracted Observation is in JSON field 'observations'.
> > > Therefore:
> > > (json \ "observations").extract[Observation]
> >
> > > Your error stack trace suggests that you have an old version of lift-
> > > json. Please upgrade to M8, there was a critical bug in case class
> > > extraction in older versions.
> >
> > > Full example which works for me:
> >
> > >   implicit val formats = net.liftweb.json.DefaultFormats
> > >   case class Notice(copyright: String, copyright_url: String,
> > > disclaimer_url: String)
> > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > String, name: String, state_time_zone: String, time_zone: String,
> > > product_name: String, state: String)
> > >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > > local_date_time: String,
> > >   local_date_time_full: String, air_temp: Option
> > > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> > >   rel_hum: Option[Int], delta_t: Option[Double],
> > > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > > [Double],
> > >   wind_spd_kmh: Option[Double], press: Option[Double],
> > > rain_trace: String)
> >
> > >   case class Observation(notice: List[Notice], header: List[Header],
> > > data: List[Data])
> >
> > >   (json \ "observations").extract[Observation]
> >
> > > Cheers Joni
> >
> > > On 3 tammi, 09:17, Randinn  wrote:
> >
> > > > I'm having a bit of trouble with Lift Json parcing, I know I'm not
> > > > doing it correctly but looking at the examples I cannot figure out
> > > > what, anyway, here is the code in question. If someone could
> point
> > > > me in the right direction that would be great, thanks in advance.
> >
> > > > class HelloWorld {
> > > >   def howdy = Welcome to hello-lift at {new
> > > > _root_.java.util.Date}
> > > > val http = new Http
> > > > val bos = new ByteArrayOutputStream
> > > > val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> > > > IDV60901.94868.json")
> > > > val rawdata = http(myRequest >>> bos)
> > > > val bs = bos.toString
> > > > val db = :/("www.bom.gov.au")
> >
> > > > val json = parse(bs)
> >
> > > > implicit val formats = net.liftweb.json.DefaultFormats
> > > >   case class Notice(copyright: String, copyright_url: String,
> > > > disclaimer_url: String)
> > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > String, name: String, state_time_zone: String,
> > > > time_zone: String, product_name: String, state:
> > > > String)
> > > >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > > > local_date_time: String,
> > > >   local_date_time_full: Int, air_temp: Double, dewpt:
> > > > Double, apparent_t: Double,
> > > >   rel_hum: Double, delta_t: Double, wind_dir: Double,
> > > > wind_spd_kt: Double, gust_kt: Double,
> > > >   wind_spd_kmh: Double, press: Double, rain_trace:
> > > > Double)
> > > >   case class Observation(notice: Notice, header: Header, data: List
> > > > [Data])
> > > > json.extract[Observation]
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Lift" group.
> To post to this group, send email to lift...@googlegroups.com.
> To unsubscribe from this group, send email to
> liftweb+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/liftweb?hl=en.
>
>
>
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scal

[Lift] Re: Parcing Json

2010-01-14 Thread Randinn
Well here is the latest iteration of the code:

http://paste.pocoo.org/show/165511/

but I'm getting this error

Compiling 11 source files to C:\Users\Randin\Documents\Development
\weather\target\classes at 1263504637934
[ERROR]weather/snippet/HelloWorld.scala:32: error: value save is not a
member of object HelloWorld.this.Observe
  Observation.save
  ^
[ERROR]one error found

I went to 2.0-M1 and did a clean install. I assume save might be the
answer, how close am I?

On Jan 4, 1:00 am, Joni Freeman  wrote:
> Google Groups does not shine in formatting code snippets. Here's nicer
> version:
>
> http://paste.pocoo.org/show/161578/
>
> Cheers Joni
>
> On 3 tammi, 12:20, Joni Freeman  wrote:
>
> > Hi,
>
> > That's almost correct. I did following changes after looking into JSON
> > content.
>
> > 1. 'notice' and 'header' are JSON arrays just like 'data'. Therefore:
> > case class Observation(notice: List[Notice], header: List[Header],
> > data: List[Data])
>
> > 2. There's optional data in JSON (some datapoints are nulls and Scala
> > Int or Double can't take null values). This can be fixed by extracting
> > into Option.
>
> > 3. The extracted Observation is in JSON field 'observations'.
> > Therefore:
> > (json \ "observations").extract[Observation]
>
> > Your error stack trace suggests that you have an old version of lift-
> > json. Please upgrade to M8, there was a critical bug in case class
> > extraction in older versions.
>
> > Full example which works for me:
>
> >   implicit val formats = net.liftweb.json.DefaultFormats
> >   case class Notice(copyright: String, copyright_url: String,
> > disclaimer_url: String)
> >   case class Header(refresh_message: String, ID: String, main_ID:
> > String, name: String, state_time_zone: String, time_zone: String,
> > product_name: String, state: String)
> >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > local_date_time: String,
> >                   local_date_time_full: String, air_temp: Option
> > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> >                   rel_hum: Option[Int], delta_t: Option[Double],
> > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > [Double],
> >                   wind_spd_kmh: Option[Double], press: Option[Double],
> > rain_trace: String)
>
> >   case class Observation(notice: List[Notice], header: List[Header],
> > data: List[Data])
>
> >   (json \ "observations").extract[Observation]
>
> > Cheers Joni
>
> > On 3 tammi, 09:17, Randinn  wrote:
>
> > > I'm having a bit of trouble with Lift Json parcing, I know I'm not
> > > doing it correctly but looking at the examples I cannot figure out
> > > what, anyway, here is the code in question. If someone could point
> > > me in the right direction that would be great, thanks in advance.
>
> > > class HelloWorld {
> > >   def howdy = Welcome to hello-lift at {new
> > > _root_.java.util.Date}
> > > val http = new Http
> > > val bos = new ByteArrayOutputStream
> > > val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> > > IDV60901.94868.json")
> > > val rawdata = http(myRequest >>> bos)
> > > val bs = bos.toString
> > > val db = :/("www.bom.gov.au")
>
> > > val json = parse(bs)
>
> > > implicit val formats = net.liftweb.json.DefaultFormats
> > >   case class Notice(copyright: String, copyright_url: String,
> > > disclaimer_url: String)
> > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > String, name: String, state_time_zone: String,
> > >                     time_zone: String, product_name: String, state:
> > > String)
> > >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > > local_date_time: String,
> > >                   local_date_time_full: Int, air_temp: Double, dewpt:
> > > Double, apparent_t: Double,
> > >                   rel_hum: Double, delta_t: Double, wind_dir: Double,
> > > wind_spd_kt: Double, gust_kt: Double,
> > >                   wind_spd_kmh: Double, press: Double, rain_trace:
> > > Double)
> > >   case class Observation(notice: Notice, header: Header, data: List
> > > [Data])
> > > json.extract[Observation]
>
>
-- 
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.




[Lift] Re: Parcing Json

2010-01-13 Thread Randinn
I assume I use the save method but am stumbling on implementing it...

On Jan 11, 5:49 pm, Joni Freeman  wrote:
> Hi,
>
> I'm sorry but I'm not totally sure what you are trying to accomplish.
> What would be the key in that map and what would be its values?
>
> Cheers Joni
>
> On 11 tammi, 03:14, Randinn  wrote:
>
> > I should explain what we are planning, the idea is to get the json
> > file into a string, parse it and save the caught information into a
> > Observation map.
>
> > On Jan 11, 11:23 am, Randinn  wrote:
>
> > > Forgive my ignorance but I was wondering why (json \
> > > "observations").extract[Observation], is it to save as a flat file?
>
> > > On Jan 4, 7:13 am, Randinn  wrote:
>
> > > > I tried some of the changes you made but not all of them, and (json\
> > > > "observations").extract[Observation], I had no idea about that one.
> > > > Thank you very much for your help, it is appreciated.
>
> > > > On Jan 4, 1:00 am, Joni Freeman  wrote:
>
> > > > > Google Groups does not shine in formatting code snippets. Here's nicer
> > > > > version:
>
> > > > >http://paste.pocoo.org/show/161578/
>
> > > > > Cheers Joni
>
> > > > > On 3 tammi, 12:20, Joni Freeman  wrote:
>
> > > > > > Hi,
>
> > > > > > That's almost correct. I did following changes after looking 
> > > > > > intoJSON
> > > > > > content.
>
> > > > > > 1. 'notice' and 'header' areJSONarrays just like 'data'. Therefore:
> > > > > > case class Observation(notice: List[Notice], header: List[Header],
> > > > > > data: List[Data])
>
> > > > > > 2. There's optional data inJSON(some datapoints are nulls and Scala
> > > > > > Int or Double can't take null values). This can be fixed by 
> > > > > > extracting
> > > > > > into Option.
>
> > > > > > 3. The extracted Observation is inJSONfield 'observations'.
> > > > > > Therefore:
> > > > > > (json\ "observations").extract[Observation]
>
> > > > > > Your error stack trace suggests that you have an old version of 
> > > > > > lift-
> > > > > >json. Please upgrade to M8, there was a critical bug in case class
> > > > > > extraction in older versions.
>
> > > > > > Full example which works for me:
>
> > > > > >   implicit val formats = net.liftweb.json.DefaultFormats
> > > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > > disclaimer_url: String)
> > > > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > > > String, name: String, state_time_zone: String, time_zone: String,
> > > > > > product_name: String, state: String)
> > > > > >   case class Data(sort_order: Int, wmo: Int, history_product: 
> > > > > > String,
> > > > > > local_date_time: String,
> > > > > >                   local_date_time_full: String, air_temp: Option
> > > > > > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> > > > > >                   rel_hum: Option[Int], delta_t: Option[Double],
> > > > > > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > > > > > [Double],
> > > > > >                   wind_spd_kmh: Option[Double], press: 
> > > > > > Option[Double],
> > > > > > rain_trace: String)
>
> > > > > >   case class Observation(notice: List[Notice], header: List[Header],
> > > > > > data: List[Data])
>
> > > > > >   (json\ "observations").extract[Observation]
>
> > > > > > Cheers Joni
>
> > > > > > On 3 tammi, 09:17, Randinn  wrote:
>
> > > > > > > I'm having a bit of trouble with LiftJsonparcing, I know I'm not
> > > > > > > doing it correctly but looking at the examples I cannot figure out
> > > > > > > what, anyway, here is the code in question. If someone could 
> > > > > > > point
> > > > > > > me in the right direction that would be great, thanks in advance.
>
> > > > > > > class HelloWorld {
> > > > > > >   def howdy = Welcome to hello-lift at {new
> > > > > > > _root_.java.util.Date}
> > > > > > > val http = new Http
> > > > > > > val bos = new ByteArrayOutputStream
> > > > > > > val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> > > > > > > IDV60901.94868.json")
> > > > > > > val rawdata = http(myRequest >>> bos)
> > > > > > > val bs = bos.toString
> > > > > > > val db = :/("www.bom.gov.au")
>
> > > > > > > valjson= parse(bs)
>
> > > > > > > implicit val formats = net.liftweb.json.DefaultFormats
> > > > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > > > disclaimer_url: String)
> > > > > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > > > > String, name: String, state_time_zone: String,
> > > > > > >                     time_zone: String, product_name: String, 
> > > > > > > state:
> > > > > > > String)
> > > > > > >   case class Data(sort_order: Int, wmo: Int, history_product: 
> > > > > > > String,
> > > > > > > local_date_time: String,
> > > > > > >                   local_date_time_full: Int, air_temp: Double, 
> > > > > > > dewpt:
> > > > > > > Double, apparent_t: Double,
> > > > > > >                   rel_hum: Double, delta_t: Double, wind_dir: 
> 

Re: [Lift] Re: Parcing Json

2010-01-11 Thread Timothy Perrett
Yeah i've been watching it for a while; not that there is anything wrong with 
mapper / jpa, but ScalaQuery appears to be a more functional design and the 
whole "its not an ORM" thing that is favoured by quite a number of people makes 
it very interesting indeed. 

Cheers, Tim

On 11 Jan 2010, at 18:38, Joni Freeman wrote:

> Tim,
> 
> ScalaQuery is a great DSL to interface relational database and to
> construct type safe SQL queries. I find that kind of approach often
> preferable compared to full blown ORMs (like Hibernate etc.) since it
> gives full control over SQL queries and does not impose any
> constraints on object model.
> 
> At the moment it is a bit difficult to use ScalaQuery with Lift since
> latest versions of ScalaQuery requires Scala 2.8. But once Lift is
> fully on 2.8 there should be no problems at all in using it in Lift
> app. ScalaQuery is still work in progress and there hasn't been any
> official release as far as I know, the documentation is also severely
> lacking.
> 
> Cheers Joni
> 
> On 11 tammi, 13:32, Timothy Perrett  wrote:
>> Hey Joni,
>> 
>> What did you think of ScalaQuery btw? Have you used it inside a lift app?
>> 
>> Cheers, Tim
>> 
>> On 11 Jan 2010, at 11:07, Joni Freeman wrote:
>> 
>>> Ok, thanks for clarification. Unfortunately my knowledge about mapper
>>> is very limited (I've previously used ScalaQuery for db persistence).
>>> Maybe someone else can answer the question better, the question being:
>>> What is the easiest way to store instances of Observations into
>>> database using mapper.
>> 
>>> case class Observation(notice: List[Notice], header: List[Header],
>>> data: List[Data])
>> 
>>> Notice, Header and Data are simple case classes having just primitive
>>> fields.
>> 
>>> Cheers Joni
>> 
>>> On 11 tammi, 10:36, Randinn  wrote:
 Sorry for the confusion Observation is a table actually, I meant to
 write mapper. So what we're doing is calling up thejsonfile, making
 it a string, putting it through the parcer and inserting it into the
 table.
>> 
 On Jan 11, 5:49 pm, Joni Freeman  wrote:
>> 
> Hi,
>> 
> I'm sorry but I'm not totally sure what you are trying to accomplish.
> What would be the key in that map and what would be its values?
>> 
> Cheers Joni
>> 
> On 11 tammi, 03:14, Randinn  wrote:
>> 
>> I should explain what we are planning, the idea is to get thejson
>> file into a string, parse it and save the caught information into a
>> Observation map.
>> 
>> On Jan 11, 11:23 am, Randinn  wrote:
>> 
>>> Forgive my ignorance but I was wondering why (json\
>>> "observations").extract[Observation], is it to save as a flat file?
>> 
>>> On Jan 4, 7:13 am, Randinn  wrote:
>> 
 I tried some of the changes you made but not all of them, and (json\
 "observations").extract[Observation], I had no idea about that one.
 Thank you very much for your help, it is appreciated.
>> 
 On Jan 4, 1:00 am, Joni Freeman  wrote:
>> 
> Google Groups does not shine in formatting code snippets. Here's nicer
> version:
>> 
> http://paste.pocoo.org/show/161578/
>> 
> Cheers Joni
>> 
> On 3 tammi, 12:20, Joni Freeman  wrote:
>> 
>> Hi,
>> 
>> That's almost correct. I did following changes after looking intoJSON
>> content.
>> 
>> 1. 'notice' and 'header' areJSONarrays just like 'data'. Therefore:
>> case class Observation(notice: List[Notice], header: List[Header],
>> data: List[Data])
>> 
>> 2. There's optional data inJSON(some datapoints are nulls and Scala
>> Int or Double can't take null values). This can be fixed by 
>> extracting
>> into Option.
>> 
>> 3. The extracted Observation is inJSONfield 'observations'.
>> Therefore:
>> (json\ "observations").extract[Observation]
>> 
>> Your error stack trace suggests that you have an old version of lift-
>> json. Please upgrade to M8, there was a critical bug in case class
>> extraction in older versions.
>> 
>> Full example which works for me:
>> 
>>   implicit val formats = net.liftweb.json.DefaultFormats
>>   case class Notice(copyright: String, copyright_url: String,
>> disclaimer_url: String)
>>   case class Header(refresh_message: String, ID: String, main_ID:
>> String, name: String, state_time_zone: String, time_zone: String,
>> product_name: String, state: String)
>>   case class Data(sort_order: Int, wmo: Int, history_product: String,
>> local_date_time: String,
>>   local_date_time_full: String, air_temp: Option
>> [Double], dewpt: Option[Double], apparent_t: Option[Double],
>>   rel_hum: Option[Int], delta_t: Option[Double],
>> wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
>> [Double],
>>  

[Lift] Re: Parcing Json

2010-01-11 Thread Joni Freeman
Tim,

ScalaQuery is a great DSL to interface relational database and to
construct type safe SQL queries. I find that kind of approach often
preferable compared to full blown ORMs (like Hibernate etc.) since it
gives full control over SQL queries and does not impose any
constraints on object model.

At the moment it is a bit difficult to use ScalaQuery with Lift since
latest versions of ScalaQuery requires Scala 2.8. But once Lift is
fully on 2.8 there should be no problems at all in using it in Lift
app. ScalaQuery is still work in progress and there hasn't been any
official release as far as I know, the documentation is also severely
lacking.

Cheers Joni

On 11 tammi, 13:32, Timothy Perrett  wrote:
> Hey Joni,
>
> What did you think of ScalaQuery btw? Have you used it inside a lift app?
>
> Cheers, Tim
>
> On 11 Jan 2010, at 11:07, Joni Freeman wrote:
>
> > Ok, thanks for clarification. Unfortunately my knowledge about mapper
> > is very limited (I've previously used ScalaQuery for db persistence).
> > Maybe someone else can answer the question better, the question being:
> > What is the easiest way to store instances of Observations into
> > database using mapper.
>
> > case class Observation(notice: List[Notice], header: List[Header],
> > data: List[Data])
>
> > Notice, Header and Data are simple case classes having just primitive
> > fields.
>
> > Cheers Joni
>
> > On 11 tammi, 10:36, Randinn  wrote:
> >> Sorry for the confusion Observation is a table actually, I meant to
> >> write mapper. So what we're doing is calling up thejsonfile, making
> >> it a string, putting it through the parcer and inserting it into the
> >> table.
>
> >> On Jan 11, 5:49 pm, Joni Freeman  wrote:
>
> >>> Hi,
>
> >>> I'm sorry but I'm not totally sure what you are trying to accomplish.
> >>> What would be the key in that map and what would be its values?
>
> >>> Cheers Joni
>
> >>> On 11 tammi, 03:14, Randinn  wrote:
>
>  I should explain what we are planning, the idea is to get thejson
>  file into a string, parse it and save the caught information into a
>  Observation map.
>
>  On Jan 11, 11:23 am, Randinn  wrote:
>
> > Forgive my ignorance but I was wondering why (json\
> > "observations").extract[Observation], is it to save as a flat file?
>
> > On Jan 4, 7:13 am, Randinn  wrote:
>
> >> I tried some of the changes you made but not all of them, and (json\
> >> "observations").extract[Observation], I had no idea about that one.
> >> Thank you very much for your help, it is appreciated.
>
> >> On Jan 4, 1:00 am, Joni Freeman  wrote:
>
> >>> Google Groups does not shine in formatting code snippets. Here's nicer
> >>> version:
>
> >>>http://paste.pocoo.org/show/161578/
>
> >>> Cheers Joni
>
> >>> On 3 tammi, 12:20, Joni Freeman  wrote:
>
>  Hi,
>
>  That's almost correct. I did following changes after looking intoJSON
>  content.
>
>  1. 'notice' and 'header' areJSONarrays just like 'data'. Therefore:
>  case class Observation(notice: List[Notice], header: List[Header],
>  data: List[Data])
>
>  2. There's optional data inJSON(some datapoints are nulls and Scala
>  Int or Double can't take null values). This can be fixed by 
>  extracting
>  into Option.
>
>  3. The extracted Observation is inJSONfield 'observations'.
>  Therefore:
>  (json\ "observations").extract[Observation]
>
>  Your error stack trace suggests that you have an old version of lift-
> json. Please upgrade to M8, there was a critical bug in case class
>  extraction in older versions.
>
>  Full example which works for me:
>
>    implicit val formats = net.liftweb.json.DefaultFormats
>    case class Notice(copyright: String, copyright_url: String,
>  disclaimer_url: String)
>    case class Header(refresh_message: String, ID: String, main_ID:
>  String, name: String, state_time_zone: String, time_zone: String,
>  product_name: String, state: String)
>    case class Data(sort_order: Int, wmo: Int, history_product: String,
>  local_date_time: String,
>                    local_date_time_full: String, air_temp: Option
>  [Double], dewpt: Option[Double], apparent_t: Option[Double],
>                    rel_hum: Option[Int], delta_t: Option[Double],
>  wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
>  [Double],
>                    wind_spd_kmh: Option[Double], press: 
>  Option[Double],
>  rain_trace: String)
>
>    case class Observation(notice: List[Notice], header: List[Header],
>  data: List[Data])
>
>    (json\ "observations").extract[Observation]
>
>  Cheers Joni
>
>  On 3 tammi, 09:17, Randinn  wrote:
>
> > I'm having a bit of trouble with LiftJsonparcing, I know I'm not

Re: [Lift] Re: Parcing Json

2010-01-11 Thread Timothy Perrett
Hey Joni,

What did you think of ScalaQuery btw? Have you used it inside a lift app?

Cheers, Tim

On 11 Jan 2010, at 11:07, Joni Freeman wrote:

> Ok, thanks for clarification. Unfortunately my knowledge about mapper
> is very limited (I've previously used ScalaQuery for db persistence).
> Maybe someone else can answer the question better, the question being:
> What is the easiest way to store instances of Observations into
> database using mapper.
> 
> case class Observation(notice: List[Notice], header: List[Header],
> data: List[Data])
> 
> Notice, Header and Data are simple case classes having just primitive
> fields.
> 
> Cheers Joni
> 
> On 11 tammi, 10:36, Randinn  wrote:
>> Sorry for the confusion Observation is a table actually, I meant to
>> write mapper. So what we're doing is calling up the json file, making
>> it a string, putting it through the parcer and inserting it into the
>> table.
>> 
>> On Jan 11, 5:49 pm, Joni Freeman  wrote:
>> 
>>> Hi,
>> 
>>> I'm sorry but I'm not totally sure what you are trying to accomplish.
>>> What would be the key in that map and what would be its values?
>> 
>>> Cheers Joni
>> 
>>> On 11 tammi, 03:14, Randinn  wrote:
>> 
 I should explain what we are planning, the idea is to get the json
 file into a string, parse it and save the caught information into a
 Observation map.
>> 
 On Jan 11, 11:23 am, Randinn  wrote:
>> 
> Forgive my ignorance but I was wondering why (json \
> "observations").extract[Observation], is it to save as a flat file?
>> 
> On Jan 4, 7:13 am, Randinn  wrote:
>> 
>> I tried some of the changes you made but not all of them, and (json\
>> "observations").extract[Observation], I had no idea about that one.
>> Thank you very much for your help, it is appreciated.
>> 
>> On Jan 4, 1:00 am, Joni Freeman  wrote:
>> 
>>> Google Groups does not shine in formatting code snippets. Here's nicer
>>> version:
>> 
>>> http://paste.pocoo.org/show/161578/
>> 
>>> Cheers Joni
>> 
>>> On 3 tammi, 12:20, Joni Freeman  wrote:
>> 
 Hi,
>> 
 That's almost correct. I did following changes after looking intoJSON
 content.
>> 
 1. 'notice' and 'header' areJSONarrays just like 'data'. Therefore:
 case class Observation(notice: List[Notice], header: List[Header],
 data: List[Data])
>> 
 2. There's optional data inJSON(some datapoints are nulls and Scala
 Int or Double can't take null values). This can be fixed by extracting
 into Option.
>> 
 3. The extracted Observation is inJSONfield 'observations'.
 Therefore:
 (json\ "observations").extract[Observation]
>> 
 Your error stack trace suggests that you have an old version of lift-
 json. Please upgrade to M8, there was a critical bug in case class
 extraction in older versions.
>> 
 Full example which works for me:
>> 
   implicit val formats = net.liftweb.json.DefaultFormats
   case class Notice(copyright: String, copyright_url: String,
 disclaimer_url: String)
   case class Header(refresh_message: String, ID: String, main_ID:
 String, name: String, state_time_zone: String, time_zone: String,
 product_name: String, state: String)
   case class Data(sort_order: Int, wmo: Int, history_product: String,
 local_date_time: String,
   local_date_time_full: String, air_temp: Option
 [Double], dewpt: Option[Double], apparent_t: Option[Double],
   rel_hum: Option[Int], delta_t: Option[Double],
 wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
 [Double],
   wind_spd_kmh: Option[Double], press: Option[Double],
 rain_trace: String)
>> 
   case class Observation(notice: List[Notice], header: List[Header],
 data: List[Data])
>> 
   (json\ "observations").extract[Observation]
>> 
 Cheers Joni
>> 
 On 3 tammi, 09:17, Randinn  wrote:
>> 
> I'm having a bit of trouble with LiftJsonparcing, I know I'm not
> doing it correctly but looking at the examples I cannot figure out
> what, anyway, here is the code in question. If someone could point
> me in the right direction that would be great, thanks in advance.
>> 
> class HelloWorld {
>   def howdy = Welcome to hello-lift at {new
> _root_.java.util.Date}
> val http = new Http
> val bos = new ByteArrayOutputStream
> val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> IDV60901.94868.json")
> val rawdata = http(myRequest >>> bos)
> val bs = bos.toString
> val db = :/("www.bom.gov.au")
>> 
> valjson= parse(bs)
>> 
> implicit val formats = net.liftweb.json.DefaultFormats
>   case class Notice(copyright: String, copyright_url: Strin

[Lift] Re: Parcing Json

2010-01-11 Thread Joni Freeman
Ok, thanks for clarification. Unfortunately my knowledge about mapper
is very limited (I've previously used ScalaQuery for db persistence).
Maybe someone else can answer the question better, the question being:
What is the easiest way to store instances of Observations into
database using mapper.

case class Observation(notice: List[Notice], header: List[Header],
data: List[Data])

Notice, Header and Data are simple case classes having just primitive
fields.

Cheers Joni

On 11 tammi, 10:36, Randinn  wrote:
> Sorry for the confusion Observation is a table actually, I meant to
> write mapper. So what we're doing is calling up the json file, making
> it a string, putting it through the parcer and inserting it into the
> table.
>
> On Jan 11, 5:49 pm, Joni Freeman  wrote:
>
> > Hi,
>
> > I'm sorry but I'm not totally sure what you are trying to accomplish.
> > What would be the key in that map and what would be its values?
>
> > Cheers Joni
>
> > On 11 tammi, 03:14, Randinn  wrote:
>
> > > I should explain what we are planning, the idea is to get the json
> > > file into a string, parse it and save the caught information into a
> > > Observation map.
>
> > > On Jan 11, 11:23 am, Randinn  wrote:
>
> > > > Forgive my ignorance but I was wondering why (json \
> > > > "observations").extract[Observation], is it to save as a flat file?
>
> > > > On Jan 4, 7:13 am, Randinn  wrote:
>
> > > > > I tried some of the changes you made but not all of them, and (json\
> > > > > "observations").extract[Observation], I had no idea about that one.
> > > > > Thank you very much for your help, it is appreciated.
>
> > > > > On Jan 4, 1:00 am, Joni Freeman  wrote:
>
> > > > > > Google Groups does not shine in formatting code snippets. Here's 
> > > > > > nicer
> > > > > > version:
>
> > > > > >http://paste.pocoo.org/show/161578/
>
> > > > > > Cheers Joni
>
> > > > > > On 3 tammi, 12:20, Joni Freeman  wrote:
>
> > > > > > > Hi,
>
> > > > > > > That's almost correct. I did following changes after looking 
> > > > > > > intoJSON
> > > > > > > content.
>
> > > > > > > 1. 'notice' and 'header' areJSONarrays just like 'data'. 
> > > > > > > Therefore:
> > > > > > > case class Observation(notice: List[Notice], header: List[Header],
> > > > > > > data: List[Data])
>
> > > > > > > 2. There's optional data inJSON(some datapoints are nulls and 
> > > > > > > Scala
> > > > > > > Int or Double can't take null values). This can be fixed by 
> > > > > > > extracting
> > > > > > > into Option.
>
> > > > > > > 3. The extracted Observation is inJSONfield 'observations'.
> > > > > > > Therefore:
> > > > > > > (json\ "observations").extract[Observation]
>
> > > > > > > Your error stack trace suggests that you have an old version of 
> > > > > > > lift-
> > > > > > >json. Please upgrade to M8, there was a critical bug in case class
> > > > > > > extraction in older versions.
>
> > > > > > > Full example which works for me:
>
> > > > > > >   implicit val formats = net.liftweb.json.DefaultFormats
> > > > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > > > disclaimer_url: String)
> > > > > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > > > > String, name: String, state_time_zone: String, time_zone: String,
> > > > > > > product_name: String, state: String)
> > > > > > >   case class Data(sort_order: Int, wmo: Int, history_product: 
> > > > > > > String,
> > > > > > > local_date_time: String,
> > > > > > >                   local_date_time_full: String, air_temp: Option
> > > > > > > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> > > > > > >                   rel_hum: Option[Int], delta_t: Option[Double],
> > > > > > > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > > > > > > [Double],
> > > > > > >                   wind_spd_kmh: Option[Double], press: 
> > > > > > > Option[Double],
> > > > > > > rain_trace: String)
>
> > > > > > >   case class Observation(notice: List[Notice], header: 
> > > > > > > List[Header],
> > > > > > > data: List[Data])
>
> > > > > > >   (json\ "observations").extract[Observation]
>
> > > > > > > Cheers Joni
>
> > > > > > > On 3 tammi, 09:17, Randinn  wrote:
>
> > > > > > > > I'm having a bit of trouble with LiftJsonparcing, I know I'm not
> > > > > > > > doing it correctly but looking at the examples I cannot figure 
> > > > > > > > out
> > > > > > > > what, anyway, here is the code in question. If someone 
> > > > > > > > could point
> > > > > > > > me in the right direction that would be great, thanks in 
> > > > > > > > advance.
>
> > > > > > > > class HelloWorld {
> > > > > > > >   def howdy = Welcome to hello-lift at {new
> > > > > > > > _root_.java.util.Date}
> > > > > > > > val http = new Http
> > > > > > > > val bos = new ByteArrayOutputStream
> > > > > > > > val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> > > > > > > > IDV60901.94868.json")
> > > > > > > > val rawdata = http(myRequest >>> bos)
> > > 

[Lift] Re: Parcing Json

2010-01-11 Thread Randinn
Sorry for the confusion Observation is a table actually, I meant to
write mapper. So what we're doing is calling up the json file, making
it a string, putting it through the parcer and inserting it into the
table.

On Jan 11, 5:49 pm, Joni Freeman  wrote:
> Hi,
>
> I'm sorry but I'm not totally sure what you are trying to accomplish.
> What would be the key in that map and what would be its values?
>
> Cheers Joni
>
> On 11 tammi, 03:14, Randinn  wrote:
>
> > I should explain what we are planning, the idea is to get the json
> > file into a string, parse it and save the caught information into a
> > Observation map.
>
> > On Jan 11, 11:23 am, Randinn  wrote:
>
> > > Forgive my ignorance but I was wondering why (json \
> > > "observations").extract[Observation], is it to save as a flat file?
>
> > > On Jan 4, 7:13 am, Randinn  wrote:
>
> > > > I tried some of the changes you made but not all of them, and (json\
> > > > "observations").extract[Observation], I had no idea about that one.
> > > > Thank you very much for your help, it is appreciated.
>
> > > > On Jan 4, 1:00 am, Joni Freeman  wrote:
>
> > > > > Google Groups does not shine in formatting code snippets. Here's nicer
> > > > > version:
>
> > > > >http://paste.pocoo.org/show/161578/
>
> > > > > Cheers Joni
>
> > > > > On 3 tammi, 12:20, Joni Freeman  wrote:
>
> > > > > > Hi,
>
> > > > > > That's almost correct. I did following changes after looking 
> > > > > > intoJSON
> > > > > > content.
>
> > > > > > 1. 'notice' and 'header' areJSONarrays just like 'data'. Therefore:
> > > > > > case class Observation(notice: List[Notice], header: List[Header],
> > > > > > data: List[Data])
>
> > > > > > 2. There's optional data inJSON(some datapoints are nulls and Scala
> > > > > > Int or Double can't take null values). This can be fixed by 
> > > > > > extracting
> > > > > > into Option.
>
> > > > > > 3. The extracted Observation is inJSONfield 'observations'.
> > > > > > Therefore:
> > > > > > (json\ "observations").extract[Observation]
>
> > > > > > Your error stack trace suggests that you have an old version of 
> > > > > > lift-
> > > > > >json. Please upgrade to M8, there was a critical bug in case class
> > > > > > extraction in older versions.
>
> > > > > > Full example which works for me:
>
> > > > > >   implicit val formats = net.liftweb.json.DefaultFormats
> > > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > > disclaimer_url: String)
> > > > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > > > String, name: String, state_time_zone: String, time_zone: String,
> > > > > > product_name: String, state: String)
> > > > > >   case class Data(sort_order: Int, wmo: Int, history_product: 
> > > > > > String,
> > > > > > local_date_time: String,
> > > > > >                   local_date_time_full: String, air_temp: Option
> > > > > > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> > > > > >                   rel_hum: Option[Int], delta_t: Option[Double],
> > > > > > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > > > > > [Double],
> > > > > >                   wind_spd_kmh: Option[Double], press: 
> > > > > > Option[Double],
> > > > > > rain_trace: String)
>
> > > > > >   case class Observation(notice: List[Notice], header: List[Header],
> > > > > > data: List[Data])
>
> > > > > >   (json\ "observations").extract[Observation]
>
> > > > > > Cheers Joni
>
> > > > > > On 3 tammi, 09:17, Randinn  wrote:
>
> > > > > > > I'm having a bit of trouble with LiftJsonparcing, I know I'm not
> > > > > > > doing it correctly but looking at the examples I cannot figure out
> > > > > > > what, anyway, here is the code in question. If someone could 
> > > > > > > point
> > > > > > > me in the right direction that would be great, thanks in advance.
>
> > > > > > > class HelloWorld {
> > > > > > >   def howdy = Welcome to hello-lift at {new
> > > > > > > _root_.java.util.Date}
> > > > > > > val http = new Http
> > > > > > > val bos = new ByteArrayOutputStream
> > > > > > > val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> > > > > > > IDV60901.94868.json")
> > > > > > > val rawdata = http(myRequest >>> bos)
> > > > > > > val bs = bos.toString
> > > > > > > val db = :/("www.bom.gov.au")
>
> > > > > > > valjson= parse(bs)
>
> > > > > > > implicit val formats = net.liftweb.json.DefaultFormats
> > > > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > > > disclaimer_url: String)
> > > > > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > > > > String, name: String, state_time_zone: String,
> > > > > > >                     time_zone: String, product_name: String, 
> > > > > > > state:
> > > > > > > String)
> > > > > > >   case class Data(sort_order: Int, wmo: Int, history_product: 
> > > > > > > String,
> > > > > > > local_date_time: String,
> > > > > > >                   local_date_time_full: Int, air_temp: Double,

[Lift] Re: Parcing Json

2010-01-10 Thread Joni Freeman
Hi,

I'm sorry but I'm not totally sure what you are trying to accomplish.
What would be the key in that map and what would be its values?

Cheers Joni

On 11 tammi, 03:14, Randinn  wrote:
> I should explain what we are planning, the idea is to get the json
> file into a string, parse it and save the caught information into a
> Observation map.
>
> On Jan 11, 11:23 am, Randinn  wrote:
>
> > Forgive my ignorance but I was wondering why (json \
> > "observations").extract[Observation], is it to save as a flat file?
>
> > On Jan 4, 7:13 am, Randinn  wrote:
>
> > > I tried some of the changes you made but not all of them, and (json\
> > > "observations").extract[Observation], I had no idea about that one.
> > > Thank you very much for your help, it is appreciated.
>
> > > On Jan 4, 1:00 am, Joni Freeman  wrote:
>
> > > > Google Groups does not shine in formatting code snippets. Here's nicer
> > > > version:
>
> > > >http://paste.pocoo.org/show/161578/
>
> > > > Cheers Joni
>
> > > > On 3 tammi, 12:20, Joni Freeman  wrote:
>
> > > > > Hi,
>
> > > > > That's almost correct. I did following changes after looking intoJSON
> > > > > content.
>
> > > > > 1. 'notice' and 'header' areJSONarrays just like 'data'. Therefore:
> > > > > case class Observation(notice: List[Notice], header: List[Header],
> > > > > data: List[Data])
>
> > > > > 2. There's optional data inJSON(some datapoints are nulls and Scala
> > > > > Int or Double can't take null values). This can be fixed by extracting
> > > > > into Option.
>
> > > > > 3. The extracted Observation is inJSONfield 'observations'.
> > > > > Therefore:
> > > > > (json\ "observations").extract[Observation]
>
> > > > > Your error stack trace suggests that you have an old version of lift-
> > > > >json. Please upgrade to M8, there was a critical bug in case class
> > > > > extraction in older versions.
>
> > > > > Full example which works for me:
>
> > > > >   implicit val formats = net.liftweb.json.DefaultFormats
> > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > disclaimer_url: String)
> > > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > > String, name: String, state_time_zone: String, time_zone: String,
> > > > > product_name: String, state: String)
> > > > >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > > > > local_date_time: String,
> > > > >                   local_date_time_full: String, air_temp: Option
> > > > > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> > > > >                   rel_hum: Option[Int], delta_t: Option[Double],
> > > > > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > > > > [Double],
> > > > >                   wind_spd_kmh: Option[Double], press: Option[Double],
> > > > > rain_trace: String)
>
> > > > >   case class Observation(notice: List[Notice], header: List[Header],
> > > > > data: List[Data])
>
> > > > >   (json\ "observations").extract[Observation]
>
> > > > > Cheers Joni
>
> > > > > On 3 tammi, 09:17, Randinn  wrote:
>
> > > > > > I'm having a bit of trouble with LiftJsonparcing, I know I'm not
> > > > > > doing it correctly but looking at the examples I cannot figure out
> > > > > > what, anyway, here is the code in question. If someone could 
> > > > > > point
> > > > > > me in the right direction that would be great, thanks in advance.
>
> > > > > > class HelloWorld {
> > > > > >   def howdy = Welcome to hello-lift at {new
> > > > > > _root_.java.util.Date}
> > > > > > val http = new Http
> > > > > > val bos = new ByteArrayOutputStream
> > > > > > val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> > > > > > IDV60901.94868.json")
> > > > > > val rawdata = http(myRequest >>> bos)
> > > > > > val bs = bos.toString
> > > > > > val db = :/("www.bom.gov.au")
>
> > > > > > valjson= parse(bs)
>
> > > > > > implicit val formats = net.liftweb.json.DefaultFormats
> > > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > > disclaimer_url: String)
> > > > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > > > String, name: String, state_time_zone: String,
> > > > > >                     time_zone: String, product_name: String, state:
> > > > > > String)
> > > > > >   case class Data(sort_order: Int, wmo: Int, history_product: 
> > > > > > String,
> > > > > > local_date_time: String,
> > > > > >                   local_date_time_full: Int, air_temp: Double, 
> > > > > > dewpt:
> > > > > > Double, apparent_t: Double,
> > > > > >                   rel_hum: Double, delta_t: Double, wind_dir: 
> > > > > > Double,
> > > > > > wind_spd_kt: Double, gust_kt: Double,
> > > > > >                   wind_spd_kmh: Double, press: Double, rain_trace:
> > > > > > Double)
> > > > > >   case class Observation(notice: Notice, header: Header, data: List
> > > > > > [Data])
> > > > > >json.extract[Observation]
-- 
You received this message because you are subscribed to the Goo

[Lift] Re: Parcing Json

2010-01-10 Thread Randinn
I should explain what we are planning, the idea is to get the json
file into a string, parse it and save the caught information into a
Observation map.

On Jan 11, 11:23 am, Randinn  wrote:
> Forgive my ignorance but I was wondering why (json \
> "observations").extract[Observation], is it to save as a flat file?
>
> On Jan 4, 7:13 am, Randinn  wrote:
>
> > I tried some of the changes you made but not all of them, and (json\
> > "observations").extract[Observation], I had no idea about that one.
> > Thank you very much for your help, it is appreciated.
>
> > On Jan 4, 1:00 am, Joni Freeman  wrote:
>
> > > Google Groups does not shine in formatting code snippets. Here's nicer
> > > version:
>
> > >http://paste.pocoo.org/show/161578/
>
> > > Cheers Joni
>
> > > On 3 tammi, 12:20, Joni Freeman  wrote:
>
> > > > Hi,
>
> > > > That's almost correct. I did following changes after looking intoJSON
> > > > content.
>
> > > > 1. 'notice' and 'header' areJSONarrays just like 'data'. Therefore:
> > > > case class Observation(notice: List[Notice], header: List[Header],
> > > > data: List[Data])
>
> > > > 2. There's optional data inJSON(some datapoints are nulls and Scala
> > > > Int or Double can't take null values). This can be fixed by extracting
> > > > into Option.
>
> > > > 3. The extracted Observation is inJSONfield 'observations'.
> > > > Therefore:
> > > > (json\ "observations").extract[Observation]
>
> > > > Your error stack trace suggests that you have an old version of lift-
> > > >json. Please upgrade to M8, there was a critical bug in case class
> > > > extraction in older versions.
>
> > > > Full example which works for me:
>
> > > >   implicit val formats = net.liftweb.json.DefaultFormats
> > > >   case class Notice(copyright: String, copyright_url: String,
> > > > disclaimer_url: String)
> > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > String, name: String, state_time_zone: String, time_zone: String,
> > > > product_name: String, state: String)
> > > >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > > > local_date_time: String,
> > > >                   local_date_time_full: String, air_temp: Option
> > > > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> > > >                   rel_hum: Option[Int], delta_t: Option[Double],
> > > > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > > > [Double],
> > > >                   wind_spd_kmh: Option[Double], press: Option[Double],
> > > > rain_trace: String)
>
> > > >   case class Observation(notice: List[Notice], header: List[Header],
> > > > data: List[Data])
>
> > > >   (json\ "observations").extract[Observation]
>
> > > > Cheers Joni
>
> > > > On 3 tammi, 09:17, Randinn  wrote:
>
> > > > > I'm having a bit of trouble with LiftJsonparcing, I know I'm not
> > > > > doing it correctly but looking at the examples I cannot figure out
> > > > > what, anyway, here is the code in question. If someone could point
> > > > > me in the right direction that would be great, thanks in advance.
>
> > > > > class HelloWorld {
> > > > >   def howdy = Welcome to hello-lift at {new
> > > > > _root_.java.util.Date}
> > > > > val http = new Http
> > > > > val bos = new ByteArrayOutputStream
> > > > > val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> > > > > IDV60901.94868.json")
> > > > > val rawdata = http(myRequest >>> bos)
> > > > > val bs = bos.toString
> > > > > val db = :/("www.bom.gov.au")
>
> > > > > valjson= parse(bs)
>
> > > > > implicit val formats = net.liftweb.json.DefaultFormats
> > > > >   case class Notice(copyright: String, copyright_url: String,
> > > > > disclaimer_url: String)
> > > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > > String, name: String, state_time_zone: String,
> > > > >                     time_zone: String, product_name: String, state:
> > > > > String)
> > > > >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > > > > local_date_time: String,
> > > > >                   local_date_time_full: Int, air_temp: Double, dewpt:
> > > > > Double, apparent_t: Double,
> > > > >                   rel_hum: Double, delta_t: Double, wind_dir: Double,
> > > > > wind_spd_kt: Double, gust_kt: Double,
> > > > >                   wind_spd_kmh: Double, press: Double, rain_trace:
> > > > > Double)
> > > > >   case class Observation(notice: Notice, header: Header, data: List
> > > > > [Data])
> > > > >json.extract[Observation]
>
>
-- 
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.




[Lift] Re: Parcing Json

2010-01-10 Thread Randinn
Forgive my ignorance but I was wondering why (json \
"observations").extract[Observation], is it to save as a flat file?

On Jan 4, 7:13 am, Randinn  wrote:
> I tried some of the changes you made but not all of them, and (json\
> "observations").extract[Observation], I had no idea about that one.
> Thank you very much for your help, it is appreciated.
>
> On Jan 4, 1:00 am, Joni Freeman  wrote:
>
> > Google Groups does not shine in formatting code snippets. Here's nicer
> > version:
>
> >http://paste.pocoo.org/show/161578/
>
> > Cheers Joni
>
> > On 3 tammi, 12:20, Joni Freeman  wrote:
>
> > > Hi,
>
> > > That's almost correct. I did following changes after looking intoJSON
> > > content.
>
> > > 1. 'notice' and 'header' areJSONarrays just like 'data'. Therefore:
> > > case class Observation(notice: List[Notice], header: List[Header],
> > > data: List[Data])
>
> > > 2. There's optional data inJSON(some datapoints are nulls and Scala
> > > Int or Double can't take null values). This can be fixed by extracting
> > > into Option.
>
> > > 3. The extracted Observation is inJSONfield 'observations'.
> > > Therefore:
> > > (json\ "observations").extract[Observation]
>
> > > Your error stack trace suggests that you have an old version of lift-
> > >json. Please upgrade to M8, there was a critical bug in case class
> > > extraction in older versions.
>
> > > Full example which works for me:
>
> > >   implicit val formats = net.liftweb.json.DefaultFormats
> > >   case class Notice(copyright: String, copyright_url: String,
> > > disclaimer_url: String)
> > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > String, name: String, state_time_zone: String, time_zone: String,
> > > product_name: String, state: String)
> > >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > > local_date_time: String,
> > >                   local_date_time_full: String, air_temp: Option
> > > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> > >                   rel_hum: Option[Int], delta_t: Option[Double],
> > > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > > [Double],
> > >                   wind_spd_kmh: Option[Double], press: Option[Double],
> > > rain_trace: String)
>
> > >   case class Observation(notice: List[Notice], header: List[Header],
> > > data: List[Data])
>
> > >   (json\ "observations").extract[Observation]
>
> > > Cheers Joni
>
> > > On 3 tammi, 09:17, Randinn  wrote:
>
> > > > I'm having a bit of trouble with LiftJsonparcing, I know I'm not
> > > > doing it correctly but looking at the examples I cannot figure out
> > > > what, anyway, here is the code in question. If someone could point
> > > > me in the right direction that would be great, thanks in advance.
>
> > > > class HelloWorld {
> > > >   def howdy = Welcome to hello-lift at {new
> > > > _root_.java.util.Date}
> > > > val http = new Http
> > > > val bos = new ByteArrayOutputStream
> > > > val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> > > > IDV60901.94868.json")
> > > > val rawdata = http(myRequest >>> bos)
> > > > val bs = bos.toString
> > > > val db = :/("www.bom.gov.au")
>
> > > > valjson= parse(bs)
>
> > > > implicit val formats = net.liftweb.json.DefaultFormats
> > > >   case class Notice(copyright: String, copyright_url: String,
> > > > disclaimer_url: String)
> > > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > > String, name: String, state_time_zone: String,
> > > >                     time_zone: String, product_name: String, state:
> > > > String)
> > > >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > > > local_date_time: String,
> > > >                   local_date_time_full: Int, air_temp: Double, dewpt:
> > > > Double, apparent_t: Double,
> > > >                   rel_hum: Double, delta_t: Double, wind_dir: Double,
> > > > wind_spd_kt: Double, gust_kt: Double,
> > > >                   wind_spd_kmh: Double, press: Double, rain_trace:
> > > > Double)
> > > >   case class Observation(notice: Notice, header: Header, data: List
> > > > [Data])
> > > >json.extract[Observation]
>
>
-- 
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.




[Lift] Re: Parcing Json

2010-01-03 Thread Randinn
I tried some of the changes you made but not all of them, and (json \
"observations").extract[Observation], I had no idea about that one.
Thank you very much for your help, it is appreciated.

On Jan 4, 1:00 am, Joni Freeman  wrote:
> Google Groups does not shine in formatting code snippets. Here's nicer
> version:
>
> http://paste.pocoo.org/show/161578/
>
> Cheers Joni
>
> On 3 tammi, 12:20, Joni Freeman  wrote:
>
> > Hi,
>
> > That's almost correct. I did following changes after looking into JSON
> > content.
>
> > 1. 'notice' and 'header' are JSON arrays just like 'data'. Therefore:
> > case class Observation(notice: List[Notice], header: List[Header],
> > data: List[Data])
>
> > 2. There's optional data in JSON (some datapoints are nulls and Scala
> > Int or Double can't take null values). This can be fixed by extracting
> > into Option.
>
> > 3. The extracted Observation is in JSON field 'observations'.
> > Therefore:
> > (json \ "observations").extract[Observation]
>
> > Your error stack trace suggests that you have an old version of lift-
> > json. Please upgrade to M8, there was a critical bug in case class
> > extraction in older versions.
>
> > Full example which works for me:
>
> >   implicit val formats = net.liftweb.json.DefaultFormats
> >   case class Notice(copyright: String, copyright_url: String,
> > disclaimer_url: String)
> >   case class Header(refresh_message: String, ID: String, main_ID:
> > String, name: String, state_time_zone: String, time_zone: String,
> > product_name: String, state: String)
> >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > local_date_time: String,
> >                   local_date_time_full: String, air_temp: Option
> > [Double], dewpt: Option[Double], apparent_t: Option[Double],
> >                   rel_hum: Option[Int], delta_t: Option[Double],
> > wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> > [Double],
> >                   wind_spd_kmh: Option[Double], press: Option[Double],
> > rain_trace: String)
>
> >   case class Observation(notice: List[Notice], header: List[Header],
> > data: List[Data])
>
> >   (json \ "observations").extract[Observation]
>
> > Cheers Joni
>
> > On 3 tammi, 09:17, Randinn  wrote:
>
> > > I'm having a bit of trouble with Lift Json parcing, I know I'm not
> > > doing it correctly but looking at the examples I cannot figure out
> > > what, anyway, here is the code in question. If someone could point
> > > me in the right direction that would be great, thanks in advance.
>
> > > class HelloWorld {
> > >   def howdy = Welcome to hello-lift at {new
> > > _root_.java.util.Date}
> > > val http = new Http
> > > val bos = new ByteArrayOutputStream
> > > val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> > > IDV60901.94868.json")
> > > val rawdata = http(myRequest >>> bos)
> > > val bs = bos.toString
> > > val db = :/("www.bom.gov.au")
>
> > > val json = parse(bs)
>
> > > implicit val formats = net.liftweb.json.DefaultFormats
> > >   case class Notice(copyright: String, copyright_url: String,
> > > disclaimer_url: String)
> > >   case class Header(refresh_message: String, ID: String, main_ID:
> > > String, name: String, state_time_zone: String,
> > >                     time_zone: String, product_name: String, state:
> > > String)
> > >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > > local_date_time: String,
> > >                   local_date_time_full: Int, air_temp: Double, dewpt:
> > > Double, apparent_t: Double,
> > >                   rel_hum: Double, delta_t: Double, wind_dir: Double,
> > > wind_spd_kt: Double, gust_kt: Double,
> > >                   wind_spd_kmh: Double, press: Double, rain_trace:
> > > Double)
> > >   case class Observation(notice: Notice, header: Header, data: List
> > > [Data])
> > > json.extract[Observation]
>
>

--

You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.




[Lift] Re: Parcing Json

2010-01-03 Thread Joni Freeman
Google Groups does not shine in formatting code snippets. Here's nicer
version:

http://paste.pocoo.org/show/161578/

Cheers Joni

On 3 tammi, 12:20, Joni Freeman  wrote:
> Hi,
>
> That's almost correct. I did following changes after looking into JSON
> content.
>
> 1. 'notice' and 'header' are JSON arrays just like 'data'. Therefore:
> case class Observation(notice: List[Notice], header: List[Header],
> data: List[Data])
>
> 2. There's optional data in JSON (some datapoints are nulls and Scala
> Int or Double can't take null values). This can be fixed by extracting
> into Option.
>
> 3. The extracted Observation is in JSON field 'observations'.
> Therefore:
> (json \ "observations").extract[Observation]
>
> Your error stack trace suggests that you have an old version of lift-
> json. Please upgrade to M8, there was a critical bug in case class
> extraction in older versions.
>
> Full example which works for me:
>
>   implicit val formats = net.liftweb.json.DefaultFormats
>   case class Notice(copyright: String, copyright_url: String,
> disclaimer_url: String)
>   case class Header(refresh_message: String, ID: String, main_ID:
> String, name: String, state_time_zone: String, time_zone: String,
> product_name: String, state: String)
>   case class Data(sort_order: Int, wmo: Int, history_product: String,
> local_date_time: String,
>                   local_date_time_full: String, air_temp: Option
> [Double], dewpt: Option[Double], apparent_t: Option[Double],
>                   rel_hum: Option[Int], delta_t: Option[Double],
> wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
> [Double],
>                   wind_spd_kmh: Option[Double], press: Option[Double],
> rain_trace: String)
>
>   case class Observation(notice: List[Notice], header: List[Header],
> data: List[Data])
>
>   (json \ "observations").extract[Observation]
>
> Cheers Joni
>
> On 3 tammi, 09:17, Randinn  wrote:
>
> > I'm having a bit of trouble with Lift Json parcing, I know I'm not
> > doing it correctly but looking at the examples I cannot figure out
> > what, anyway, here is the code in question. If someone could point
> > me in the right direction that would be great, thanks in advance.
>
> > class HelloWorld {
> >   def howdy = Welcome to hello-lift at {new
> > _root_.java.util.Date}
> > val http = new Http
> > val bos = new ByteArrayOutputStream
> > val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> > IDV60901.94868.json")
> > val rawdata = http(myRequest >>> bos)
> > val bs = bos.toString
> > val db = :/("www.bom.gov.au")
>
> > val json = parse(bs)
>
> > implicit val formats = net.liftweb.json.DefaultFormats
> >   case class Notice(copyright: String, copyright_url: String,
> > disclaimer_url: String)
> >   case class Header(refresh_message: String, ID: String, main_ID:
> > String, name: String, state_time_zone: String,
> >                     time_zone: String, product_name: String, state:
> > String)
> >   case class Data(sort_order: Int, wmo: Int, history_product: String,
> > local_date_time: String,
> >                   local_date_time_full: Int, air_temp: Double, dewpt:
> > Double, apparent_t: Double,
> >                   rel_hum: Double, delta_t: Double, wind_dir: Double,
> > wind_spd_kt: Double, gust_kt: Double,
> >                   wind_spd_kmh: Double, press: Double, rain_trace:
> > Double)
> >   case class Observation(notice: Notice, header: Header, data: List
> > [Data])
> > json.extract[Observation]

--

You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.




[Lift] Re: Parcing Json

2010-01-03 Thread Joni Freeman
Hi,

That's almost correct. I did following changes after looking into JSON
content.

1. 'notice' and 'header' are JSON arrays just like 'data'. Therefore:
case class Observation(notice: List[Notice], header: List[Header],
data: List[Data])

2. There's optional data in JSON (some datapoints are nulls and Scala
Int or Double can't take null values). This can be fixed by extracting
into Option.

3. The extracted Observation is in JSON field 'observations'.
Therefore:
(json \ "observations").extract[Observation]

Your error stack trace suggests that you have an old version of lift-
json. Please upgrade to M8, there was a critical bug in case class
extraction in older versions.

Full example which works for me:

  implicit val formats = net.liftweb.json.DefaultFormats
  case class Notice(copyright: String, copyright_url: String,
disclaimer_url: String)
  case class Header(refresh_message: String, ID: String, main_ID:
String, name: String, state_time_zone: String, time_zone: String,
product_name: String, state: String)
  case class Data(sort_order: Int, wmo: Int, history_product: String,
local_date_time: String,
  local_date_time_full: String, air_temp: Option
[Double], dewpt: Option[Double], apparent_t: Option[Double],
  rel_hum: Option[Int], delta_t: Option[Double],
wind_dir: String, wind_spd_kt: Option[Double], gust_kt: Option
[Double],
  wind_spd_kmh: Option[Double], press: Option[Double],
rain_trace: String)

  case class Observation(notice: List[Notice], header: List[Header],
data: List[Data])

  (json \ "observations").extract[Observation]

Cheers Joni

On 3 tammi, 09:17, Randinn  wrote:
> I'm having a bit of trouble with Lift Json parcing, I know I'm not
> doing it correctly but looking at the examples I cannot figure out
> what, anyway, here is the code in question. If someone could point
> me in the right direction that would be great, thanks in advance.
>
> class HelloWorld {
>   def howdy = Welcome to hello-lift at {new
> _root_.java.util.Date}
> val http = new Http
> val bos = new ByteArrayOutputStream
> val myRequest = new Request("http://www.bom.gov.au/fwo/IDV60901/
> IDV60901.94868.json")
> val rawdata = http(myRequest >>> bos)
> val bs = bos.toString
> val db = :/("www.bom.gov.au")
>
> val json = parse(bs)
>
> implicit val formats = net.liftweb.json.DefaultFormats
>   case class Notice(copyright: String, copyright_url: String,
> disclaimer_url: String)
>   case class Header(refresh_message: String, ID: String, main_ID:
> String, name: String, state_time_zone: String,
>                     time_zone: String, product_name: String, state:
> String)
>   case class Data(sort_order: Int, wmo: Int, history_product: String,
> local_date_time: String,
>                   local_date_time_full: Int, air_temp: Double, dewpt:
> Double, apparent_t: Double,
>                   rel_hum: Double, delta_t: Double, wind_dir: Double,
> wind_spd_kt: Double, gust_kt: Double,
>                   wind_spd_kmh: Double, press: Double, rain_trace:
> Double)
>   case class Observation(notice: Notice, header: Header, data: List
> [Data])
> json.extract[Observation]
>

--

You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.