[Lift] Re: lift-json serialization

2010-02-08 Thread Joni Freeman
Hi,

Serialization feature is actually a very thin layer on top of
decompose and extract functions. So, one way to accomplish that is to
use directly those functions and map the field names.

So, instead of this:

write(x, out)

Try this:

val json = decompose(x) map {
  case JField(firstname, x) = JField(fn, x)
  case JField(lastname, x) = JField(ln, x)
  case x = x
}
compact(render(json), out)

And instead of this:

read[Users](x)

Try this:

parse(x).extract[Users] map {
  case JField(fn, x) = JField(firstname, x)
  case JField(ln, x) = JField(lastname, x)
  case x = x
}

Would that solve your issue?

Cheers Joni


On Feb 9, 6:27 am, harryh har...@gmail.com wrote:
 A feature request.  Right now I might have a case class like so:

 case class User(firstname: String, lastname: String)

 which serializes to something like:

 { firstname : Harry, lastname : Heymann }

 but I happen to be serializing a lot of People and I hate to use 17
 bytes per item for the field names.  I'd really prefer to only use 4:

 { fn : Harry, ln : Heymann }

 It seems to me that through clever use of an implicit parameter I
 ought to be pass in a Map of field name - shortened names.  Thoughts?

 -harryh

-- 
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: lift-Json doesn't appear to be correctly handling attributes.

2010-02-04 Thread Joni Freeman
Thanks,

The fix is on review board now. Should be in master pretty soon. Note,
I made two changes to the test case you provided.

The expected result of example1 is:
{word:content,self:http://localhost:8080/word/
example,term:example,available:true}

The transformation converts XML attributes to fields in resulting JSON
object. The reason for this rule is that it keeps transformation more
stable. That is, these both will generate structurally equivalent
JSON:
wordfoo/word  - {word:foo}
word attr=barfoo/word   - {word:foo,attr:bar}

The expected result of example2 is:
{word:null,self:http://localhost:8080/word/
example,term:example,available:true}

Field word is null since there's no content: word .../word

Cheers Joni


On Feb 3, 11:31 pm, Jonathan Ferguson j...@spiralarm.com wrote:
 Thanks Joni,

 I've opened a ticket  http://github.com/dpp/liftweb/issues/issue/323.

 Cheers
 Jono

 On 3 February 2010 17:46, Joni Freeman freeman.j...@gmail.com wrote:

  Hi Jonathan,

  Yes, definitely a bug. Could you please open a ticket (http://
  github.com/dpp/liftweb/issues) and I will take a look at it. And
  thanks for the test case!

  Cheers Joni

  On Feb 3, 3:41 am, Jonathan Ferguson j...@spiralarm.com wrote:
   When converting XML to Json attributes are being lost, given the below
  XML
   document, we would expect
   {word:{word:content,self:http://localhost:8080/word/example
   ,term:example,available:true}}
   where as we get {word:content}
   example XML:
   word term=example self=http://localhost:8080/word/example;
   available=truecontent/word

   This is been tested on M1 and trunk.

   Thanks in advance.

   To repeat

   // From the command line, adjust paths as needed

   $scala -cp

  /Users/jono/.m2/repository/com/thoughtworks/paranamer/paranamer/2.0/paranamer-2.0.jar:/Users/jono/.m2/repository/net/liftweb/lift-json/2.0-SNAPSHOT/lift-json-2.0-SNAPSHOT.jar

   import scala.xml._
   import net.liftweb.json.JsonAST._
   import net.liftweb.json.Printer
   import net.liftweb.json.Xml

   val example1 = word term=example self=
 http://localhost:8080/word/example;
   available=truecontent/word
   val expected1 = {word:{word:content,self:
 http://localhost:8080/word/example
  ,term:example,available:true}}
   val got1 = Printer.compact(render(Xml.toJson(example1)))

   val example2 = word term=example self=
 http://localhost:8080/word/example;
   available=true/word
   val expected2 = {word:{word:content,self:
 http://localhost:8080/word/example
  ,term:example,available:true}}
   val got2 = Printer.compact(render(Xml.toJson(example2)))

   // Add to src/test/scala/net/liftweb/json/XmlBugs.scala

     Jono's XML with attributes parses correctly in {
   val example1 = word term=example self=
 http://localhost:8080/word/example;
   available=truecontent/word
   val expected1 = {word:{word:content,self:
 http://localhost:8080/word/example
  ,term:example,available:true}}

   val example2 = word term=example self=
 http://localhost:8080/word/example;
   available=true/word
   val expected2 = {word:{word:content,self:
 http://localhost:8080/word/example
  ,term:example,available:true}}

       Printer.compact(render(toJson(example1))) mustEqual expected1
       Printer.compact(render(toJson(example2))) mustEqual expected2
     }

   Here is what I get when I run the example provided.

   $scala -cp

  /Users/jono/.m2/repository/com/thoughtworks/paranamer/paranamer/2.0/paranamer-2.0.jar:/Users/jono/.m2/repository/net/liftweb/lift-json/2.0-SNAPSHOT/lift-json-2.0-SNAPSHOT.jar
   Welcome to Scala version 2.7.7.final (Java HotSpot(TM) 64-Bit Server VM,
   Java 1.6.0_17).
   Type in expressions to have them evaluated.
   Type :help for more information.

   scala import scala.xml._
   import scala.xml._

   scala import net.liftweb.json.JsonAST._
   import net.liftweb.json.JsonAST._

   scala import net.liftweb.json.Printer
   import net.liftweb.json.Printer

   scala import net.liftweb.json.Xml
   import net.liftweb.json.Xml

   scala

   scala val example1 = word term=example self=
 http://localhost:8080/word/example; available=truecontent/word
   example1: scala.xml.Elem = word self=
 http://localhost:8080/word/example;
   term=example available=truecontent/word

   scala val expected1 = {word:{word:content,self:
 http://localhost:8080/word/example
  ,term:example,available:true}}
   expected1: java.lang.String = {word:{word:content,self:
 http://localhost:8080/word/example,term:example,available:true}}

   scala val got1 = Printer.compact(render(Xml.toJson(example1)))
   got1: String = {word:content}

   scala

   Jono

   P.S I thought I had a fix, but it broke one of HarryH's tests.

   scala

   scala val example2 = word term=example self=
 http://localhost:8080/word/example; available=true/word
   example2: scala.xml.Elem = word self=
 http://localhost:8080/word/example;
   term=example available=true/word

   scala val expected2 = {word:{word:content,self:
 http://localhost:8080/word/example
  

Re: [Lift] Re: lift-Json doesn't appear to be correctly handling attributes.

2010-02-03 Thread Jonathan Ferguson
Thanks Joni,

I've opened a ticket  http://github.com/dpp/liftweb/issues/issue/323.

Cheers
Jono

On 3 February 2010 17:46, Joni Freeman freeman.j...@gmail.com wrote:

 Hi Jonathan,

 Yes, definitely a bug. Could you please open a ticket (http://
 github.com/dpp/liftweb/issues) and I will take a look at it. And
 thanks for the test case!

 Cheers Joni

 On Feb 3, 3:41 am, Jonathan Ferguson j...@spiralarm.com wrote:
  When converting XML to Json attributes are being lost, given the below
 XML
  document, we would expect
  {word:{word:content,self:http://localhost:8080/word/example
  ,term:example,available:true}}
  where as we get {word:content}
  example XML:
  word term=example self=http://localhost:8080/word/example;
  available=truecontent/word
 
  This is been tested on M1 and trunk.
 
  Thanks in advance.
 
  To repeat
 
  // From the command line, adjust paths as needed
 
  $scala -cp
 
 /Users/jono/.m2/repository/com/thoughtworks/paranamer/paranamer/2.0/paranamer-2.0.jar:/Users/jono/.m2/repository/net/liftweb/lift-json/2.0-SNAPSHOT/lift-json-2.0-SNAPSHOT.jar
 
  import scala.xml._
  import net.liftweb.json.JsonAST._
  import net.liftweb.json.Printer
  import net.liftweb.json.Xml
 
  val example1 = word term=example self=
 http://localhost:8080/word/example;
  available=truecontent/word
  val expected1 = {word:{word:content,self:
 http://localhost:8080/word/example
 ,term:example,available:true}}
  val got1 = Printer.compact(render(Xml.toJson(example1)))
 
  val example2 = word term=example self=
 http://localhost:8080/word/example;
  available=true/word
  val expected2 = {word:{word:content,self:
 http://localhost:8080/word/example
 ,term:example,available:true}}
  val got2 = Printer.compact(render(Xml.toJson(example2)))
 
  // Add to src/test/scala/net/liftweb/json/XmlBugs.scala
 
Jono's XML with attributes parses correctly in {
  val example1 = word term=example self=
 http://localhost:8080/word/example;
  available=truecontent/word
  val expected1 = {word:{word:content,self:
 http://localhost:8080/word/example
 ,term:example,available:true}}
 
  val example2 = word term=example self=
 http://localhost:8080/word/example;
  available=true/word
  val expected2 = {word:{word:content,self:
 http://localhost:8080/word/example
 ,term:example,available:true}}
 
  Printer.compact(render(toJson(example1))) mustEqual expected1
  Printer.compact(render(toJson(example2))) mustEqual expected2
}
 
  Here is what I get when I run the example provided.
 
  $scala -cp
 
 /Users/jono/.m2/repository/com/thoughtworks/paranamer/paranamer/2.0/paranamer-2.0.jar:/Users/jono/.m2/repository/net/liftweb/lift-json/2.0-SNAPSHOT/lift-json-2.0-SNAPSHOT.jar
  Welcome to Scala version 2.7.7.final (Java HotSpot(TM) 64-Bit Server VM,
  Java 1.6.0_17).
  Type in expressions to have them evaluated.
  Type :help for more information.
 
  scala import scala.xml._
  import scala.xml._
 
  scala import net.liftweb.json.JsonAST._
  import net.liftweb.json.JsonAST._
 
  scala import net.liftweb.json.Printer
  import net.liftweb.json.Printer
 
  scala import net.liftweb.json.Xml
  import net.liftweb.json.Xml
 
  scala
 
  scala val example1 = word term=example self=
 http://localhost:8080/word/example; available=truecontent/word
  example1: scala.xml.Elem = word self=
 http://localhost:8080/word/example;
  term=example available=truecontent/word
 
  scala val expected1 = {word:{word:content,self:
 http://localhost:8080/word/example
 ,term:example,available:true}}
  expected1: java.lang.String = {word:{word:content,self:
 http://localhost:8080/word/example,term:example,available:true}}
 
  scala val got1 = Printer.compact(render(Xml.toJson(example1)))
  got1: String = {word:content}
 
  scala
 
  Jono
 
  P.S I thought I had a fix, but it broke one of HarryH's tests.
 
  scala
 
  scala val example2 = word term=example self=
 http://localhost:8080/word/example; available=true/word
  example2: scala.xml.Elem = word self=
 http://localhost:8080/word/example;
  term=example available=true/word
 
  scala val expected2 = {word:{word:content,self:
 http://localhost:8080/word/example
 ,term:example,available:true}}
  expected2: java.lang.String = {word:{word:content,self:
 http://localhost:8080/word/example,term:example,available:true}}
 
  scala val got2 = Printer.compact(render(Xml.toJson(example2)))
  got2: String = {word:null}
 
  scala

 --
 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.comliftweb%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/liftweb?hl=en.



-- 
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 

[Lift] Re: lift-json and illegal field names

2009-12-10 Thread harryh
Thx all!  Just couldn't remember that little trick.

-harryh

--

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.




Re: [Lift] Re: lift-json escaping bug

2009-12-01 Thread Ross Mellgren
Fixed:

d977c95589fbd5de8bc45e43c2867097dd75a807

-Ross

On Nov 30, 2009, at 8:33 PM, harryh wrote:

 Done:
 
 http://github.com/dpp/liftweb/issues/#issue/214
 
 On Nov 30, 6:33 pm, Ross Mellgren dri...@gmail.com wrote:
 If you file an issue on github I'll write up a patch for you tonight.
 
 -Ross
 
 On Nov 30, 2009, at 6:30 PM, harryh wrote:
 
 Yes, what Ross said.  Further, taking a look at JsonParser.scala the
 bug appears to be on line ~202 where there are a couple of missing
 escape sequences: \/ as well as \f.
 
 -harryh
 
 On Nov 30, 6:20 pm, Ross Mellgren dri...@gmail.com wrote:
 He's double escaping so that scala's string interpretation will put a
 raw \ in there, so that it's an escaped forward slash (\/) to the  
 JSON
 parson, as I understand it. The output should be either invalid  
 escape
 or forward slash, but not backslash unless the input was \\.
 
 -Ross
 
 On Nov 30, 2009, at 6:18 PM, Peter Robinett wrote:
 
 Harry, I think you're double-escaping the slash. This works:
 scala import net.liftweb.json._
 scala val s1 = { \id\: \America/New_York\ }
 s1: java.lang.String = { id: America/New_York }
 
 scala JsonParser.parse(s1)
 res0: net.liftweb.json.JsonAST.JValue = JObject(List(JField
 (id,JString
 (America/New_York
 
 Peter Robinett
 
 On Nov 30, 2:16 pm, harryh har...@gmail.com wrote:
 scala import net.liftweb.json._
 scala val s2 = { \id\: \America\\/New_York\ }
 s2: java.lang.String = { id: America\/New_York }
 
 scala JsonParser.parse(s2)
 res1: net.liftweb.json.JsonAST.JValue = JObject(List(JField
 (id,JString
 (America\New_York
 
 It should be America/New_York but for some reason getting a \  
 instead
 of a /
 
 -harryh
 
 --
 
 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 
 athttp://groups.google.com/group/liftweb?hl=en
 .
 
 --
 
 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 
 athttp://groups.google.com/group/liftweb?hl=en
 .
 
 --
 
 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.
 
 

--

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: lift-json escaping bug

2009-11-30 Thread Peter Robinett
Harry, I think you're double-escaping the slash. This works:
scala import net.liftweb.json._
scala val s1 = { \id\: \America/New_York\ }
s1: java.lang.String = { id: America/New_York }

scala JsonParser.parse(s1)
res0: net.liftweb.json.JsonAST.JValue = JObject(List(JField(id,JString
(America/New_York

Peter Robinett

On Nov 30, 2:16 pm, harryh har...@gmail.com wrote:
 scala import net.liftweb.json._
 scala val s2 = { \id\: \America\\/New_York\ }
 s2: java.lang.String = { id: America\/New_York }

 scala JsonParser.parse(s2)
 res1: net.liftweb.json.JsonAST.JValue = JObject(List(JField(id,JString
 (America\New_York

 It should be America/New_York but for some reason getting a \ instead
 of a /

 -harryh

--

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.




Re: [Lift] Re: lift-json escaping bug

2009-11-30 Thread Ross Mellgren
He's double escaping so that scala's string interpretation will put a  
raw \ in there, so that it's an escaped forward slash (\/) to the JSON  
parson, as I understand it. The output should be either invalid escape  
or forward slash, but not backslash unless the input was \\.

-Ross

On Nov 30, 2009, at 6:18 PM, Peter Robinett wrote:

 Harry, I think you're double-escaping the slash. This works:
 scala import net.liftweb.json._
 scala val s1 = { \id\: \America/New_York\ }
 s1: java.lang.String = { id: America/New_York }

 scala JsonParser.parse(s1)
 res0: net.liftweb.json.JsonAST.JValue = JObject(List(JField(id,JString
 (America/New_York

 Peter Robinett

 On Nov 30, 2:16 pm, harryh har...@gmail.com wrote:
 scala import net.liftweb.json._
 scala val s2 = { \id\: \America\\/New_York\ }
 s2: java.lang.String = { id: America\/New_York }

 scala JsonParser.parse(s2)
 res1: net.liftweb.json.JsonAST.JValue = JObject(List(JField 
 (id,JString
 (America\New_York

 It should be America/New_York but for some reason getting a \ instead
 of a /

 -harryh

 --

 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 
 .



--

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: lift-json escaping bug

2009-11-30 Thread harryh
Yes, what Ross said.  Further, taking a look at JsonParser.scala the
bug appears to be on line ~202 where there are a couple of missing
escape sequences: \/ as well as \f.

-harryh

On Nov 30, 6:20 pm, Ross Mellgren dri...@gmail.com wrote:
 He's double escaping so that scala's string interpretation will put a  
 raw \ in there, so that it's an escaped forward slash (\/) to the JSON  
 parson, as I understand it. The output should be either invalid escape  
 or forward slash, but not backslash unless the input was \\.

 -Ross

 On Nov 30, 2009, at 6:18 PM, Peter Robinett wrote:

  Harry, I think you're double-escaping the slash. This works:
  scala import net.liftweb.json._
  scala val s1 = { \id\: \America/New_York\ }
  s1: java.lang.String = { id: America/New_York }

  scala JsonParser.parse(s1)
  res0: net.liftweb.json.JsonAST.JValue = JObject(List(JField(id,JString
  (America/New_York

  Peter Robinett

  On Nov 30, 2:16 pm, harryh har...@gmail.com wrote:
  scala import net.liftweb.json._
  scala val s2 = { \id\: \America\\/New_York\ }
  s2: java.lang.String = { id: America\/New_York }

  scala JsonParser.parse(s2)
  res1: net.liftweb.json.JsonAST.JValue = JObject(List(JField
  (id,JString
  (America\New_York

  It should be America/New_York but for some reason getting a \ instead
  of a /

  -harryh

  --

  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 
  athttp://groups.google.com/group/liftweb?hl=en
  .

--

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.




Re: [Lift] Re: lift-json escaping bug

2009-11-30 Thread Ross Mellgren
If you file an issue on github I'll write up a patch for you tonight.

-Ross

On Nov 30, 2009, at 6:30 PM, harryh wrote:

 Yes, what Ross said.  Further, taking a look at JsonParser.scala the
 bug appears to be on line ~202 where there are a couple of missing
 escape sequences: \/ as well as \f.

 -harryh

 On Nov 30, 6:20 pm, Ross Mellgren dri...@gmail.com wrote:
 He's double escaping so that scala's string interpretation will put a
 raw \ in there, so that it's an escaped forward slash (\/) to the  
 JSON
 parson, as I understand it. The output should be either invalid  
 escape
 or forward slash, but not backslash unless the input was \\.

 -Ross

 On Nov 30, 2009, at 6:18 PM, Peter Robinett wrote:

 Harry, I think you're double-escaping the slash. This works:
 scala import net.liftweb.json._
 scala val s1 = { \id\: \America/New_York\ }
 s1: java.lang.String = { id: America/New_York }

 scala JsonParser.parse(s1)
 res0: net.liftweb.json.JsonAST.JValue = JObject(List(JField 
 (id,JString
 (America/New_York

 Peter Robinett

 On Nov 30, 2:16 pm, harryh har...@gmail.com wrote:
 scala import net.liftweb.json._
 scala val s2 = { \id\: \America\\/New_York\ }
 s2: java.lang.String = { id: America\/New_York }

 scala JsonParser.parse(s2)
 res1: net.liftweb.json.JsonAST.JValue = JObject(List(JField
 (id,JString
 (America\New_York

 It should be America/New_York but for some reason getting a \  
 instead
 of a /

 -harryh

 --

 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 
 athttp://groups.google.com/group/liftweb?hl=en
 .

 --

 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 
 .



--

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: lift-json escaping bug

2009-11-30 Thread Nathan Folkman (Foursquare)
Here's the complete list from http://json.org/:

char:

Any Unicode character except  or \ or control-character.

\
\\
\/
\b
\f
\n
\r
\t
\u four-hex-digits

- n

On Nov 30, 6:30 pm, harryh har...@gmail.com wrote:
 Yes, what Ross said.  Further, taking a look at JsonParser.scala the
 bug appears to be on line ~202 where there are a couple of missing
 escape sequences: \/ as well as \f.

 -harryh

 On Nov 30, 6:20 pm, Ross Mellgren dri...@gmail.com wrote:



  He's double escaping so that scala's string interpretation will put a  
  raw \ in there, so that it's an escaped forward slash (\/) to the JSON  
  parson, as I understand it. The output should be either invalid escape  
  or forward slash, but not backslash unless the input was \\.

  -Ross

  On Nov 30, 2009, at 6:18 PM, Peter Robinett wrote:

   Harry, I think you're double-escaping the slash. This works:
   scala import net.liftweb.json._
   scala val s1 = { \id\: \America/New_York\ }
   s1: java.lang.String = { id: America/New_York }

   scala JsonParser.parse(s1)
   res0: net.liftweb.json.JsonAST.JValue = JObject(List(JField(id,JString
   (America/New_York

   Peter Robinett

   On Nov 30, 2:16 pm, harryh har...@gmail.com wrote:
   scala import net.liftweb.json._
   scala val s2 = { \id\: \America\\/New_York\ }
   s2: java.lang.String = { id: America\/New_York }

   scala JsonParser.parse(s2)
   res1: net.liftweb.json.JsonAST.JValue = JObject(List(JField
   (id,JString
   (America\New_York

   It should be America/New_York but for some reason getting a \ instead
   of a /

   -harryh

   --

   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 
   athttp://groups.google.com/group/liftweb?hl=en
   .

--

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.




Re: [Lift] Re: lift-json escaping bug

2009-11-30 Thread Ross Mellgren
What I find particularly interesting is that the JSON spec lacks \',  
but gains \/, relative to the ECMA-262 (javascript) spec that JSON  
supposedly derives from.

-Ross

On Nov 30, 2009, at 6:34 PM, Nathan Folkman (Foursquare) wrote:

 Here's the complete list from http://json.org/:

 char:

 Any Unicode character except  or \ or control-character.

 \
 \\
 \/
 \b
 \f
 \n
 \r
 \t
 \u four-hex-digits

 - n

 On Nov 30, 6:30 pm, harryh har...@gmail.com wrote:
 Yes, what Ross said.  Further, taking a look at JsonParser.scala the
 bug appears to be on line ~202 where there are a couple of missing
 escape sequences: \/ as well as \f.

 -harryh

 On Nov 30, 6:20 pm, Ross Mellgren dri...@gmail.com wrote:



 He's double escaping so that scala's string interpretation will  
 put a
 raw \ in there, so that it's an escaped forward slash (\/) to the  
 JSON
 parson, as I understand it. The output should be either invalid  
 escape
 or forward slash, but not backslash unless the input was \\.

 -Ross

 On Nov 30, 2009, at 6:18 PM, Peter Robinett wrote:

 Harry, I think you're double-escaping the slash. This works:
 scala import net.liftweb.json._
 scala val s1 = { \id\: \America/New_York\ }
 s1: java.lang.String = { id: America/New_York }

 scala JsonParser.parse(s1)
 res0: net.liftweb.json.JsonAST.JValue = JObject(List(JField 
 (id,JString
 (America/New_York

 Peter Robinett

 On Nov 30, 2:16 pm, harryh har...@gmail.com wrote:
 scala import net.liftweb.json._
 scala val s2 = { \id\: \America\\/New_York\ }
 s2: java.lang.String = { id: America\/New_York }

 scala JsonParser.parse(s2)
 res1: net.liftweb.json.JsonAST.JValue = JObject(List(JField
 (id,JString
 (America\New_York

 It should be America/New_York but for some reason getting a \  
 instead
 of a /

 -harryh

 --

 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 
 athttp://groups.google.com/group/liftweb?hl=en
 .

 --

 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 
 .



--

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: lift-json escaping bug

2009-11-30 Thread harryh
Done:

http://github.com/dpp/liftweb/issues/#issue/214

On Nov 30, 6:33 pm, Ross Mellgren dri...@gmail.com wrote:
 If you file an issue on github I'll write up a patch for you tonight.

 -Ross

 On Nov 30, 2009, at 6:30 PM, harryh wrote:

  Yes, what Ross said.  Further, taking a look at JsonParser.scala the
  bug appears to be on line ~202 where there are a couple of missing
  escape sequences: \/ as well as \f.

  -harryh

  On Nov 30, 6:20 pm, Ross Mellgren dri...@gmail.com wrote:
  He's double escaping so that scala's string interpretation will put a
  raw \ in there, so that it's an escaped forward slash (\/) to the  
  JSON
  parson, as I understand it. The output should be either invalid  
  escape
  or forward slash, but not backslash unless the input was \\.

  -Ross

  On Nov 30, 2009, at 6:18 PM, Peter Robinett wrote:

  Harry, I think you're double-escaping the slash. This works:
  scala import net.liftweb.json._
  scala val s1 = { \id\: \America/New_York\ }
  s1: java.lang.String = { id: America/New_York }

  scala JsonParser.parse(s1)
  res0: net.liftweb.json.JsonAST.JValue = JObject(List(JField
  (id,JString
  (America/New_York

  Peter Robinett

  On Nov 30, 2:16 pm, harryh har...@gmail.com wrote:
  scala import net.liftweb.json._
  scala val s2 = { \id\: \America\\/New_York\ }
  s2: java.lang.String = { id: America\/New_York }

  scala JsonParser.parse(s2)
  res1: net.liftweb.json.JsonAST.JValue = JObject(List(JField
  (id,JString
  (America\New_York

  It should be America/New_York but for some reason getting a \  
  instead
  of a /

  -harryh

  --

  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 
  athttp://groups.google.com/group/liftweb?hl=en
  .

  --

  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 
  athttp://groups.google.com/group/liftweb?hl=en
  .

--

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.




Re: [Lift] Re: lift-json escaping bug

2009-11-30 Thread Ross Mellgren
On review board: http://reviewboard.liftweb.net/r/131/

I did run across another infelicity when writing the test -- apparently 
JsonParser crashes when given a scalar value, as opposed to an array or object:

scala parse(\foobar\)
net.liftweb.json.JsonParser$ParseException: unexpected null
Near: foobar
at net.liftweb.json.JsonParser$Parser.fail(JsonParser.scala:166)
at net.liftweb.json.JsonParser$ValStack.peek(JsonParser.scala:153)
at net.liftweb.json.JsonParser$.newValue$1(JsonParser.scala:110)
at net.liftweb.json.JsonParser$.parse0(JsonParser.scala:125)
at net.liftweb.json.JsonParser$.parse(JsonParser.s...

I'm not sure if it should work, but even if it shouldn't support that the error 
case should probably give a better message. Joni/et al?

-Ross

On Nov 30, 2009, at 8:33 PM, harryh wrote:

 Done:
 
 http://github.com/dpp/liftweb/issues/#issue/214
 
 On Nov 30, 6:33 pm, Ross Mellgren dri...@gmail.com wrote:
 If you file an issue on github I'll write up a patch for you tonight.
 
 -Ross
 
 On Nov 30, 2009, at 6:30 PM, harryh wrote:
 
 Yes, what Ross said.  Further, taking a look at JsonParser.scala the
 bug appears to be on line ~202 where there are a couple of missing
 escape sequences: \/ as well as \f.
 
 -harryh
 
 On Nov 30, 6:20 pm, Ross Mellgren dri...@gmail.com wrote:
 He's double escaping so that scala's string interpretation will put a
 raw \ in there, so that it's an escaped forward slash (\/) to the  
 JSON
 parson, as I understand it. The output should be either invalid  
 escape
 or forward slash, but not backslash unless the input was \\.
 
 -Ross
 
 On Nov 30, 2009, at 6:18 PM, Peter Robinett wrote:
 
 Harry, I think you're double-escaping the slash. This works:
 scala import net.liftweb.json._
 scala val s1 = { \id\: \America/New_York\ }
 s1: java.lang.String = { id: America/New_York }
 
 scala JsonParser.parse(s1)
 res0: net.liftweb.json.JsonAST.JValue = JObject(List(JField
 (id,JString
 (America/New_York
 
 Peter Robinett
 
 On Nov 30, 2:16 pm, harryh har...@gmail.com wrote:
 scala import net.liftweb.json._
 scala val s2 = { \id\: \America\\/New_York\ }
 s2: java.lang.String = { id: America\/New_York }
 
 scala JsonParser.parse(s2)
 res1: net.liftweb.json.JsonAST.JValue = JObject(List(JField
 (id,JString
 (America\New_York
 
 It should be America/New_York but for some reason getting a \  
 instead
 of a /
 
 -harryh
 
 --
 
 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 
 athttp://groups.google.com/group/liftweb?hl=en
 .
 
 --
 
 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 
 athttp://groups.google.com/group/liftweb?hl=en
 .
 
 --
 
 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.
 
 

--

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: lift-json escaping bug

2009-11-30 Thread Joni Freeman
Hi,

This is from JSON RFC (http://www.ietf.org/rfc/rfc4627.txt): A JSON
text is a serialized object or array.

I checked with another parser (http://www.jsonlint.com) and it fails
too when given just JSON value:
syntax error, unexpected TNUMBER, expecting '{' or '[' at line 1

So perhaps a better error message is a proper fix here?

Cheers Joni

On 1 joulu, 05:22, Ross Mellgren dri...@gmail.com wrote:
 On review board:http://reviewboard.liftweb.net/r/131/

 I did run across another infelicity when writing the test -- apparently 
 JsonParser crashes when given a scalar value, as opposed to an array or 
 object:

 scala parse(\foobar\)
 net.liftweb.json.JsonParser$ParseException: unexpected null
 Near: foobar
         at net.liftweb.json.JsonParser$Parser.fail(JsonParser.scala:166)
         at net.liftweb.json.JsonParser$ValStack.peek(JsonParser.scala:153)
         at net.liftweb.json.JsonParser$.newValue$1(JsonParser.scala:110)
         at net.liftweb.json.JsonParser$.parse0(JsonParser.scala:125)
         at net.liftweb.json.JsonParser$.parse(JsonParser.s...

 I'm not sure if it should work, but even if it shouldn't support that the 
 error case should probably give a better message. Joni/et al?

 -Ross

 On Nov 30, 2009, at 8:33 PM, harryh wrote:

  Done:

 http://github.com/dpp/liftweb/issues/#issue/214

  On Nov 30, 6:33 pm, Ross Mellgren dri...@gmail.com wrote:
  If you file an issue on github I'll write up a patch for you tonight.

  -Ross

  On Nov 30, 2009, at 6:30 PM, harryh wrote:

  Yes, what Ross said.  Further, taking a look at JsonParser.scala the
  bug appears to be on line ~202 where there are a couple of missing
  escape sequences: \/ as well as \f.

  -harryh

  On Nov 30, 6:20 pm, Ross Mellgren dri...@gmail.com wrote:
  He's double escaping so that scala's string interpretation will put a
  raw \ in there, so that it's an escaped forward slash (\/) to the  
  JSON
  parson, as I understand it. The output should be either invalid  
  escape
  or forward slash, but not backslash unless the input was \\.

  -Ross

  On Nov 30, 2009, at 6:18 PM, Peter Robinett wrote:

  Harry, I think you're double-escaping the slash. This works:
  scala import net.liftweb.json._
  scala val s1 = { \id\: \America/New_York\ }
  s1: java.lang.String = { id: America/New_York }

  scala JsonParser.parse(s1)
  res0: net.liftweb.json.JsonAST.JValue = JObject(List(JField
  (id,JString
  (America/New_York

  Peter Robinett

  On Nov 30, 2:16 pm, harryh har...@gmail.com wrote:
  scala import net.liftweb.json._
  scala val s2 = { \id\: \America\\/New_York\ }
  s2: java.lang.String = { id: America\/New_York }

  scala JsonParser.parse(s2)
  res1: net.liftweb.json.JsonAST.JValue = JObject(List(JField
  (id,JString
  (America\New_York

  It should be America/New_York but for some reason getting a \  
  instead
  of a /

  -harryh

  --

  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 
  athttp://groups.google.com/group/liftweb?hl=en
  .

  --

  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 
  athttp://groups.google.com/group/liftweb?hl=en
  .

  --

  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 
  athttp://groups.google.com/group/liftweb?hl=en.

--

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: lift-json question related to Lists of things

2009-11-25 Thread Joni Freeman
Hi,

Totally agreed, this makes List extraction more robust. The change is
in reviewboard now:

http://reviewboard.liftweb.net/r/127/

Cheers Joni

On 25 marras, 20:42, harryh har...@gmail.com wrote:
 consider:

 case class Foo(id: Int, bars: List[Bar])
 case class Bar(id: Int)

 val foo = json.extract[Foo]

 The following json will cause a problem:

 {
   id: 12

 }

 This can be fixed by changing bars to an Option[List[Bar]].  Should
 that really be necessary though?  Can't bars just be an empty list if
 there are none of them?

 -harryh

--

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: lift-json bug (in Xml.toJson)

2009-11-11 Thread David Pollak
I think a fix to this was pushed this morning.  Once this job is finished:
http://hudson.scala-tools.org/job/Lift/1367/ It should be available on
SNAPSHOT.


On Tue, Nov 10, 2009 at 1:49 PM, harryh har...@gmail.com wrote:


 This is on M7:

 scala import
 scala.xml.Elem
 import scala.xml.Elem

 scala import
 net.liftweb.json.JsonAST._
 import net.liftweb.json.JsonAST._

 scala import
 net.liftweb.json._
 import net.liftweb.json._

 scala def go(e: Elem) = Printer.pretty(render(Xml.toJson
 (e)))
 go: (scala.xml.Elem)String

 scala tipsgroup type=Nearbytipid10/id/tip/group/
 tips
 res0: scala.xml.Elem = tipsgroup type=Nearbytipid10/id/
 tip/group/tips

 scala go
 (res0)
 res1: String = { tips:{ group:{ type:Nearby, tip:
 { id:10 } }, type:Nearby } }

 Note how Nearby appears twice in res1 but only once in res0

 -harryh

 



-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@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: lift-json serialization primitive types

2009-11-02 Thread Joni Freeman

Hi,

Custom serialization and deserialization functions are now supported
in trunk. Please see updated docs in section Serializing non-
supported types:

http://github.com/dpp/liftweb/tree/master/lift-base/lift-json/

Cheers Joni


On 25 loka, 14:27, Christophe Dehlinger
christophedehlin...@gmail.com wrote:
 Hi,

 Is there a way to configure lift-json's case class serialization so that it
 uses Joda DateTimes instead of java.util.Date ?
 I'd like to known how to make the simple following code work as expected:

 import net.liftweb.json._
 import org.joda.time._

 case class MyCaseClass(dt: DateTime)

 object TestMain {
   def main(args: Array[String]) {
     implicit val formats = DefaultFormats
     println(Serialization.read[MyCaseClass]({ dt :
 2009-10-25T12:50:37.560+01:00 }))
     println(Serialization.write(MyCaseClass(new DateTime)))
   }

 }

 (running this code yields:
 MyCaseClass(2009-10-25T12:57:03.366+01:00)  -- current date when the
 program was run, not the date in the code
 {}
 )

 More generally, is there a way to customize lift-json's serialization
 mappings, in particular the types lift-json sees as primitive ?
 The class I'm actually interested in serializing has many fields whose type
 is a non-case class MyRichFloat with a single Float field. It would be
 really nice if I could (de)serialize these into JSON floats.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@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: lift-json serialization primitive types

2009-10-25 Thread Joni Freeman

Hi,

Serializing joda-time is not supported. Last week a type hint
mechanism was added to support serialization of polymorphic Lists.
This could be generalized a bit so that users can provide de-/
serializers for any type. This could be done for instance using a pair
of partial functions. Something like:

type TypeHint = String

def serialize: PartialFunction[Any, JValue]
def deserialize: PartialFunction[(TypeHint, JValue), Any]

Then a support to serialize joda-time DateTime could be implemented
as:

def serialize(a: Any) = a match {
  case d: DateTime = JString(t, toString(d))
}

def deserialize(hint: TypeHint, json: JValue) = (hint, json) match {
  case (DateTime, JString(t, JString(t)) = mkDateTime(t)
}

I'm in a middle of something else right now but will look into this
next.

Cheers Joni

On 25 loka, 14:27, Christophe Dehlinger
christophedehlin...@gmail.com wrote:
 Hi,

 Is there a way to configure lift-json's case class serialization so that it
 uses Joda DateTimes instead of java.util.Date ?
 I'd like to known how to make the simple following code work as expected:

 import net.liftweb.json._
 import org.joda.time._

 case class MyCaseClass(dt: DateTime)

 object TestMain {
   def main(args: Array[String]) {
     implicit val formats = DefaultFormats
     println(Serialization.read[MyCaseClass]({ dt :
 2009-10-25T12:50:37.560+01:00 }))
     println(Serialization.write(MyCaseClass(new DateTime)))
   }

 }

 (running this code yields:
 MyCaseClass(2009-10-25T12:57:03.366+01:00)  -- current date when the
 program was run, not the date in the code
 {}
 )

 More generally, is there a way to customize lift-json's serialization
 mappings, in particular the types lift-json sees as primitive ?
 The class I'm actually interested in serializing has many fields whose type
 is a non-case class MyRichFloat with a single Float field. It would be
 really nice if I could (de)serialize these into JSON floats.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@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: lift-json and attributes

2009-10-07 Thread Richard Dallaway

On Mon, Oct 5, 2009 at 9:01 PM, Joni Freeman freeman.j...@gmail.com wrote:

 Thanks Richard!

 This is a feature request and I just committed an implementation to my
 branch.

I've just pulled 1-1 SNAPSHOT, tried it, and it works just how I need it to.

Thank you
Richard

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@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: lift-json and attributes

2009-10-06 Thread harryh

 This is a feature request and I just committed an implementation to my
 branch.

This looks great.  If there is anyway it could get committed to master
in time for M6 (which is coming out any day now right?) that would be
very very helpful to me.

Thanks for your work on this stuff Joni!

-harryh
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@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: lift-json and attributes

2009-10-06 Thread David Pollak
On Tue, Oct 6, 2009 at 9:03 AM, harryh har...@gmail.com wrote:


  This is a feature request and I just committed an implementation to my
  branch.

 This looks great.  If there is anyway it could get committed to master
 in time for M6 (which is coming out any day now right?) that would be
 very very helpful to me.


Sorry.  We froze on Sunday. :-(


 Thanks for your work on this stuff Joni!

 -harryh
 



-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@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: lift-json and attributes

2009-10-05 Thread Joni Freeman

Thanks Richard!

This is a feature request and I just committed an implementation to my
branch. I modified existing example to contain few attributes to show
how they are mapped:

http://github.com/dpp/liftweb/blob/joni_wip_xml/lift-json/src/test/scala/net/liftweb/json/XmlExamples.scala

If other committers give it the green light I will push it to master.

Cheers Joni

On Oct 5, 5:41 pm, Richard Dallaway dalla...@gmail.com wrote:
 Loving the new lift-json code.  We've been producing XML for a REST
 API, and now need to produce JSON.  lift-json to the rescue,
 except...the Xml converter doesn't handle attributes:

 scala val xml = user id=7nameBert/name/user
 xml: scala.xml.Elem = user id=7nameBert/name/user

 scala val json = toJson(xml)
 json: net.liftweb.json.JsonAST.JValue =
 JObject(List(JField(user,JObject(List(JField(name,JString(Bert)))

 scala JsonDSL.compact(JsonAST.render(json))
 res5: String = {user:{name:Bert}}

 I'd expect res5 to be something like:  {user:{id:7,name:Bert}}

 I'm either missing a clue, or this is a feature request.

 I can see there's ambiguity in how you might map the above JSON back
 to XML with attributes, but it seems reasonable that if you have XML +
 attributes they would be present in a JSON representation.

 Thank you
 Richard
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@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: lift-json serialization

2009-09-24 Thread Joni Freeman

Tim,

Extracted function is now in master. I renamed it as 'decompose' since
it decomposes case class into JSON AST.

Thanks again, Joni

On Sep 21, 6:52 pm, Tim Nelson tnell...@gmail.com wrote:
 First of all thanks for a great library. I'm finding lift-json quite useful
 in my current project.

 I have a use case where I need to convert a case class into a JObject. The
 code is there, but it's wrapped inside the Serialization object. So, I took
 the liberty of moving the serialize method to the Extraction object and made
 it publicly accessible. You can see my changes here:

 http://github.com/eltimn/liftweb/commit/30310f4800b2aeb880b246e99dc79...

 It doesn't affect the current API at all and all tests passed. What do you
 think?

 Feel free to move it wherever you think it should be. As long as it's
 publicly accessible, I'll be happy.

 Thanks,
 Tim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@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: lift-json serialization

2009-09-24 Thread Tim Nelson
Excellent. Thanks.

On Thu, Sep 24, 2009 at 2:21 AM, Joni Freeman freeman.j...@gmail.comwrote:


 Tim,

 Extracted function is now in master. I renamed it as 'decompose' since
 it decomposes case class into JSON AST.

 Thanks again, Joni

 On Sep 21, 6:52 pm, Tim Nelson tnell...@gmail.com wrote:
  First of all thanks for a great library. I'm finding lift-json quite
 useful
  in my current project.
 
  I have a use case where I need to convert a case class into a JObject.
 The
  code is there, but it's wrapped inside the Serialization object. So, I
 took
  the liberty of moving the serialize method to the Extraction object and
 made
  it publicly accessible. You can see my changes here:
 
  http://github.com/eltimn/liftweb/commit/30310f4800b2aeb880b246e99dc79...
 
  It doesn't affect the current API at all and all tests passed. What do
 you
  think?
 
  Feel free to move it wherever you think it should be. As long as it's
  publicly accessible, I'll be happy.
 
  Thanks,
  Tim
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@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: lift-json serialization

2009-09-21 Thread Joni Freeman

Hi Tim,

Thanks for the kind words! The serialization functions should already
be publicly accessible, you just need to import them into scope:

import net.liftweb.json.Serialization.{read, write}

val ser = write(...)

val obj = read[..](ser)

Cheers Joni

On Sep 21, 6:52 pm, Tim Nelson tnell...@gmail.com wrote:
 First of all thanks for a great library. I'm finding lift-json quite useful
 in my current project.

 I have a use case where I need to convert a case class into a JObject. The
 code is there, but it's wrapped inside the Serialization object. So, I took
 the liberty of moving the serialize method to the Extraction object and made
 it publicly accessible. You can see my changes here:

 http://github.com/eltimn/liftweb/commit/30310f4800b2aeb880b246e99dc79...

 It doesn't affect the current API at all and all tests passed. What do you
 think?

 Feel free to move it wherever you think it should be. As long as it's
 publicly accessible, I'll be happy.

 Thanks,
 Tim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@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: lift-json serialization

2009-09-21 Thread Joni Freeman

Oh, I see the point now and agree that this is useful. Let's add thia
to API. Thanks a lot!

Cheers Joni

On Sep 21, 6:52 pm, Tim Nelson tnell...@gmail.com wrote:
 First of all thanks for a great library. I'm finding lift-json quite useful
 in my current project.

 I have a use case where I need to convert a case class into a JObject. The
 code is there, but it's wrapped inside the Serialization object. So, I took
 the liberty of moving the serialize method to the Extraction object and made
 it publicly accessible. You can see my changes here:

 http://github.com/eltimn/liftweb/commit/30310f4800b2aeb880b246e99dc79...

 It doesn't affect the current API at all and all tests passed. What do you
 think?

 Feel free to move it wherever you think it should be. As long as it's
 publicly accessible, I'll be happy.

 Thanks,
 Tim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@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: lift-json

2009-09-13 Thread Lincoln
Sorry, here's the full code I'm using:

case class MyName(first:String, last:String)
case class MyUser(id:String, name:MyName, url:String) {
  val wtf = wtf
}

implicit val formats = net.liftweb.json.DefaultFormats
val json =
(id - me.id) ~
(name -
(first - me.name.first) ~
(last - me.name.last)
) ~
(url - me.url)
val output = JsonDSL.pretty(render(json))
val jsonCopy = parse(output)
val user = jsonCopy.extract[MyUser]
println(user = +user)




On Sun, Sep 13, 2009 at 12:07 AM, linxbetter linxbet...@gmail.com wrote:

 Hello, I saw a post about lift-json on the scala-user list so I
 decided to check it out.  I was particularly interested in the ability
 to call something along the lines of json.extract[MyClass].  I set up
 a little test case for this though, and apparently having a val of any
 sort in my case class causes the below exception.  Any thoughts?

 My classes looked like this:
 case class MyName(first:String, last:String)
 case class MyUser(id:String, name:MyName, url:String) {
  val wtf = wtf
 }

 And the output of my test

 [info]   lift-json should
 [info]   x do pain-free json conversion on nested objects
 net.liftweb.json.MappingException: Expected JField but got JNothing,
 json='JField(name,JObject(List(JField(first,JString(Lincoln)), JField
 (last,JString(Hochberg)', path='wtf'
at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$
 $fail(Extraction.scala:151)
at net.liftweb.json.Extraction$.fieldValue$1(Extraction.scala:
 106)
at net.liftweb.json.Extraction$.build$1(Extraction.scala:78)
at net.liftweb.json.Extraction$$anonfun$1.apply
 (Extraction.scala:84)
at net.liftweb.json.Extraction$$anonfun$1.apply
 (Extraction.scala:84)
at scala.List.flatMap(List.scala:1132)
at net.liftweb.json.Extraction$.build$1(Extraction.scala:84)
at net.liftweb.json.Extraction$$anonfun$1.apply
 (Extraction.scala:84)
at net.liftweb.json.Extraction$$anonfun$1.apply
 (Extraction.scala:84)
at scala.List.flatMap(List.scala:1132)
at net.liftweb.json.Extraction$.build$1(Extraction.scala:84)
at net.liftweb.json.Extraction$.extract0(Extraction.scala:109)
at net.liftweb.json.Extraction$.extract(Extraction.scala:60)
at net.liftweb.json.JsonAST$JValue.extract(Json.scala:109)
at com.hotpotato.core.SerializationSpec$$anonfun$1$$anonfun
 $apply$1.apply(SerializationSpec.scala:87)
at com.hotpotato.core.SerializationSpec$$anonfun$1$$anonfun
 $apply$1.apply(SerializationSpec.scala:69)
at org.specs.specification.ExampleExecution$$anonfun$3$$anonfun
 $apply$1.apply(Example.scala:207)
at org.specs.specification.Example.execute(Example.scala:121)
at org.specs.specification.ExampleLifeCycle$class.executeTest
 (ExampleLifeCycle.scala:20)
at org.specs.Specification.executeTest(Specification.scala:28)
at org.specs.specification.Sus.executeTest(Sus.scala:147)
at org.specs.specification.ExampleExecution$$anonfun$3.apply
 (Example.scala:207)
at org.specs.specification.ExampleExecution$$anonfun$3.apply
 (Example.scala:194)
at org.specs.specification.ExampleExecution$$anonfun$2.apply
 (Example.scala:185)
at org.specs.specification.ExampleExecution.execute
 (Example.scala:227)
at org.specs.specification.Example.execute(Example.scala:117)
at org.specs.specification.Example.errors(Example.scala:143)
at org.specs.specification.Sus$$anonfun$successes$1.apply
 (Sus.scala:122)
at org.specs.specification.Sus$$anonfun$successes$1.apply
 (Sus.scala:122)
at scala.List.filter(List.scala:859)
at org.specs.specification.Sus.successes(Sus.scala:122)
at org.specs.Specification$$anonfun$successes$1.apply
 (Specification.scala:84)
at org.specs.Specification$$anonfun$successes$1.apply
 (Specification.scala:84)
at scala.List.flatMap(List.scala:1132)
at org.specs.Specification.successes(Specification.scala:84)
at sbt.impl.SpecsRunner.sbt$impl$SpecsRunner$
 $reportSpecification(TestFrameworkImpl.scala:140)
at sbt.impl.SpecsRunner.runTest(TestFrameworkImpl.scala:123)
at sbt.BasicTestRunner.run(TestFramework.scala:38)
at sbt.TestFramework$$anonfun$7$$anonfun$apply$8.runTest$1
 (TestFramework.scala:136)
at sbt.TestFramework$$anonfun$7$$anonfun$apply$8$$anonfun$apply
 $9.apply(TestFramework.scala:147)
at sbt.TestFramework$$anonfun$7$$anonfun$apply$8$$anonfun$apply
 $9.apply(TestFramework.scala:147)
at sbt.NamedTestTask.run(TestFramework.scala:57)
at sbt.ScalaProject$$anonfun$sbt$ScalaProject$$toTask$1.apply
 (ScalaProject.scala:167)
at sbt.ScalaProject$$anonfun$sbt$ScalaProject$$toTask$1.apply
 (ScalaProject.scala:167)
at sbt.TaskManager$Task.invoke(TaskManager.scala:62)
at sbt.impl.RunTask.runTask(RunTask.scala:78)
at sbt.impl.RunTask.sbt$impl$RunTask$$runIfNotRoot
 (RunTask.scala:63)
  

[Lift] Re: lift-json

2009-09-13 Thread Joni Freeman

Hi,

Your example should work if you take the val away from your case
class:

case class MyName(first:String, last:String)
case class MyUser(id:String, name:MyName, url:String)

The reflection code currently fails to find the primary constructor of
case class if there's extra fields. This will hopefully be fixed some
day when the reflection story of Scala gets better (using Java
reflection is very awkward).

Cheers Joni

On Sep 13, 7:55 am, Lincoln linxbet...@gmail.com wrote:
 Sorry, here's the full code I'm using:

 case class MyName(first:String, last:String)
 case class MyUser(id:String, name:MyName, url:String) {
   val wtf = wtf

 }

 implicit val formats = net.liftweb.json.DefaultFormats
 val json =
 (id - me.id) ~
 (name -
 (first - me.name.first) ~
 (last - me.name.last)
 ) ~
 (url - me.url)
 val output = JsonDSL.pretty(render(json))
 val jsonCopy = parse(output)
 val user = jsonCopy.extract[MyUser]
 println(user = +user)

 On Sun, Sep 13, 2009 at 12:07 AM, linxbetter linxbet...@gmail.com wrote:
  Hello, I saw a post about lift-json on the scala-user list so I
  decided to check it out.  I was particularly interested in the ability
  to call something along the lines of json.extract[MyClass].  I set up
  a little test case for this though, and apparently having a val of any
  sort in my case class causes the below exception.  Any thoughts?

  My classes looked like this:
  case class MyName(first:String, last:String)
  case class MyUser(id:String, name:MyName, url:String) {
   val wtf = wtf
  }

  And the output of my test

  [info]   lift-json should
  [info]   x do pain-free json conversion on nested objects
  net.liftweb.json.MappingException: Expected JField but got JNothing,
  json='JField(name,JObject(List(JField(first,JString(Lincoln)), JField
  (last,JString(Hochberg)', path='wtf'
         at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$
  $fail(Extraction.scala:151)
         at net.liftweb.json.Extraction$.fieldValue$1(Extraction.scala:
  106)
         at net.liftweb.json.Extraction$.build$1(Extraction.scala:78)
         at net.liftweb.json.Extraction$$anonfun$1.apply
  (Extraction.scala:84)
         at net.liftweb.json.Extraction$$anonfun$1.apply
  (Extraction.scala:84)
         at scala.List.flatMap(List.scala:1132)
         at net.liftweb.json.Extraction$.build$1(Extraction.scala:84)
         at net.liftweb.json.Extraction$$anonfun$1.apply
  (Extraction.scala:84)
         at net.liftweb.json.Extraction$$anonfun$1.apply
  (Extraction.scala:84)
         at scala.List.flatMap(List.scala:1132)
         at net.liftweb.json.Extraction$.build$1(Extraction.scala:84)
         at net.liftweb.json.Extraction$.extract0(Extraction.scala:109)
         at net.liftweb.json.Extraction$.extract(Extraction.scala:60)
         at net.liftweb.json.JsonAST$JValue.extract(Json.scala:109)
         at com.hotpotato.core.SerializationSpec$$anonfun$1$$anonfun
  $apply$1.apply(SerializationSpec.scala:87)
         at com.hotpotato.core.SerializationSpec$$anonfun$1$$anonfun
  $apply$1.apply(SerializationSpec.scala:69)
         at org.specs.specification.ExampleExecution$$anonfun$3$$anonfun
  $apply$1.apply(Example.scala:207)
         at org.specs.specification.Example.execute(Example.scala:121)
         at org.specs.specification.ExampleLifeCycle$class.executeTest
  (ExampleLifeCycle.scala:20)
         at org.specs.Specification.executeTest(Specification.scala:28)
         at org.specs.specification.Sus.executeTest(Sus.scala:147)
         at org.specs.specification.ExampleExecution$$anonfun$3.apply
  (Example.scala:207)
         at org.specs.specification.ExampleExecution$$anonfun$3.apply
  (Example.scala:194)
         at org.specs.specification.ExampleExecution$$anonfun$2.apply
  (Example.scala:185)
         at org.specs.specification.ExampleExecution.execute
  (Example.scala:227)
         at org.specs.specification.Example.execute(Example.scala:117)
         at org.specs.specification.Example.errors(Example.scala:143)
         at org.specs.specification.Sus$$anonfun$successes$1.apply
  (Sus.scala:122)
         at org.specs.specification.Sus$$anonfun$successes$1.apply
  (Sus.scala:122)
         at scala.List.filter(List.scala:859)
         at org.specs.specification.Sus.successes(Sus.scala:122)
         at org.specs.Specification$$anonfun$successes$1.apply
  (Specification.scala:84)
         at org.specs.Specification$$anonfun$successes$1.apply
  (Specification.scala:84)
         at scala.List.flatMap(List.scala:1132)
         at org.specs.Specification.successes(Specification.scala:84)
         at sbt.impl.SpecsRunner.sbt$impl$SpecsRunner$
  $reportSpecification(TestFrameworkImpl.scala:140)
         at sbt.impl.SpecsRunner.runTest(TestFrameworkImpl.scala:123)
         at sbt.BasicTestRunner.run(TestFramework.scala:38)
         at sbt.TestFramework$$anonfun$7$$anonfun$apply$8.runTest$1
  (TestFramework.scala:136)
         at sbt.TestFramework$$anonfun$7$$anonfun$apply$8$$anonfun$apply
  

[Lift] Re: lift-json

2009-09-13 Thread Lincoln
Got it.  Thanks for the info.  I was afraid I was doing something wrong.
Thanks,
Lincoln

On Sun, Sep 13, 2009 at 9:48 AM, Joni Freeman freeman.j...@gmail.comwrote:


 Hi,

 Your example should work if you take the val away from your case
 class:

 case class MyName(first:String, last:String)
 case class MyUser(id:String, name:MyName, url:String)

 The reflection code currently fails to find the primary constructor of
 case class if there's extra fields. This will hopefully be fixed some
 day when the reflection story of Scala gets better (using Java
 reflection is very awkward).

 Cheers Joni

 On Sep 13, 7:55 am, Lincoln linxbet...@gmail.com wrote:
  Sorry, here's the full code I'm using:
 
  case class MyName(first:String, last:String)
  case class MyUser(id:String, name:MyName, url:String) {
val wtf = wtf
 
  }
 
  implicit val formats = net.liftweb.json.DefaultFormats
  val json =
  (id - me.id) ~
  (name -
  (first - me.name.first) ~
  (last - me.name.last)
  ) ~
  (url - me.url)
  val output = JsonDSL.pretty(render(json))
  val jsonCopy = parse(output)
  val user = jsonCopy.extract[MyUser]
  println(user = +user)
 
  On Sun, Sep 13, 2009 at 12:07 AM, linxbetter linxbet...@gmail.com
 wrote:
   Hello, I saw a post about lift-json on the scala-user list so I
   decided to check it out.  I was particularly interested in the ability
   to call something along the lines of json.extract[MyClass].  I set up
   a little test case for this though, and apparently having a val of any
   sort in my case class causes the below exception.  Any thoughts?
 
   My classes looked like this:
   case class MyName(first:String, last:String)
   case class MyUser(id:String, name:MyName, url:String) {
val wtf = wtf
   }
 
   And the output of my test
 
   [info]   lift-json should
   [info]   x do pain-free json conversion on nested objects
   net.liftweb.json.MappingException: Expected JField but got JNothing,
   json='JField(name,JObject(List(JField(first,JString(Lincoln)), JField
   (last,JString(Hochberg)', path='wtf'
  at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$
   $fail(Extraction.scala:151)
  at net.liftweb.json.Extraction$.fieldValue$1(Extraction.scala:
   106)
  at net.liftweb.json.Extraction$.build$1(Extraction.scala:78)
  at net.liftweb.json.Extraction$$anonfun$1.apply
   (Extraction.scala:84)
  at net.liftweb.json.Extraction$$anonfun$1.apply
   (Extraction.scala:84)
  at scala.List.flatMap(List.scala:1132)
  at net.liftweb.json.Extraction$.build$1(Extraction.scala:84)
  at net.liftweb.json.Extraction$$anonfun$1.apply
   (Extraction.scala:84)
  at net.liftweb.json.Extraction$$anonfun$1.apply
   (Extraction.scala:84)
  at scala.List.flatMap(List.scala:1132)
  at net.liftweb.json.Extraction$.build$1(Extraction.scala:84)
  at net.liftweb.json.Extraction$.extract0(Extraction.scala:109)
  at net.liftweb.json.Extraction$.extract(Extraction.scala:60)
  at net.liftweb.json.JsonAST$JValue.extract(Json.scala:109)
  at com.hotpotato.core.SerializationSpec$$anonfun$1$$anonfun
   $apply$1.apply(SerializationSpec.scala:87)
  at com.hotpotato.core.SerializationSpec$$anonfun$1$$anonfun
   $apply$1.apply(SerializationSpec.scala:69)
  at org.specs.specification.ExampleExecution$$anonfun$3$$anonfun
   $apply$1.apply(Example.scala:207)
  at org.specs.specification.Example.execute(Example.scala:121)
  at org.specs.specification.ExampleLifeCycle$class.executeTest
   (ExampleLifeCycle.scala:20)
  at org.specs.Specification.executeTest(Specification.scala:28)
  at org.specs.specification.Sus.executeTest(Sus.scala:147)
  at org.specs.specification.ExampleExecution$$anonfun$3.apply
   (Example.scala:207)
  at org.specs.specification.ExampleExecution$$anonfun$3.apply
   (Example.scala:194)
  at org.specs.specification.ExampleExecution$$anonfun$2.apply
   (Example.scala:185)
  at org.specs.specification.ExampleExecution.execute
   (Example.scala:227)
  at org.specs.specification.Example.execute(Example.scala:117)
  at org.specs.specification.Example.errors(Example.scala:143)
  at org.specs.specification.Sus$$anonfun$successes$1.apply
   (Sus.scala:122)
  at org.specs.specification.Sus$$anonfun$successes$1.apply
   (Sus.scala:122)
  at scala.List.filter(List.scala:859)
  at org.specs.specification.Sus.successes(Sus.scala:122)
  at org.specs.Specification$$anonfun$successes$1.apply
   (Specification.scala:84)
  at org.specs.Specification$$anonfun$successes$1.apply
   (Specification.scala:84)
  at scala.List.flatMap(List.scala:1132)
  at org.specs.Specification.successes(Specification.scala:84)
  at sbt.impl.SpecsRunner.sbt$impl$SpecsRunner$
   $reportSpecification(TestFrameworkImpl.scala:140)
  at