You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Vanio Meurer <va...@gmail.com> on 2011/01/28 01:36:46 UTC

How parse a JSON to List

Hello, how I can parse a JSON to List<Bean>?
Or how I can get the List<Bean> with GetQuery?
I really tried a lot of ways, but I don't have success.
-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/How-parse-a-JSON-to-List-Bean-tp2364779p2364779.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: where is com.kitfox.svg.SVGDiagram?

Posted by Sandro Martini <sa...@gmail.com>.
Hi Greg,

> The SVG Salamander library is required to build the platform - it just isn't required at runtime if you don't use the Drawing class.
Ok. Maybe in the future we can think to move only the wtk drawing part
in a dedicated jar ... let's see later.

Bye

Re: where is com.kitfox.svg.SVGDiagram?

Posted by Greg Brown <gk...@verizon.net>.
>> It is optional - it is only necessary if you want to use a Drawing in your app.
> Yes, I agree but as explained here (
> http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
> ) could be a good addition as optional dependency.

The SVG Salamander library is required to build the platform - it just isn't required at runtime if you don't use the Drawing class.

G


Re: where is com.kitfox.svg.SVGDiagram?

Posted by Sandro Martini <sa...@gmail.com>.
Hi Greg,

2011/1/31 Greg Brown <gk...@verizon.net>:
>> just seen the same issue even in the Maven version of downloaded jars:
>> in the 2.0.1 I'll add the (optional if possible) dependency on
>> SVGSalamander to WTK.
>
> It is optional - it is only necessary if you want to use a Drawing in your app.
Yes, I agree but as explained here (
http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
) could be a good addition as optional dependency.

Take a look at this (from that page):

Why use optional dependencies?

It's not only important to declare optional dependencies in order to
save space/memory/etc. It's vital to control the list of actual
dependencies a person needs in order to use a project, since these
jars may eventually make it into a WAR, EAR, EJB, etc. Inclusion of
the wrong jars may violate a license agreement, cause classpath
issues, etc.
How do I use the optional tag?

A dependency is declared as optional by simply setting the <optional>
tag to true in your dependency declaration.



So, is it Ok for you (and others) ?
Tell me so I can fix it (I've already found the maven repository and
data for referring to svgSalamander), so now I have to make some tests
(for example if the remote repository is not reachable, if Pivot
artifacts will be downloaded and working the same, etc), but I think
the fix will be simple.


Otherwise (probably a more long-term solution) could be to split out
the drawing part of wtk in a dedicated subproject (with its jar) with
their dependencies ... maybe for 2.1 or 3.0 .

Probably could be useful to open a jira ticket for it, and put there
all these info, so we can see when/how to do with this ...
Comments ?


Bye

Re: where is com.kitfox.svg.SVGDiagram?

Posted by Greg Brown <gk...@verizon.net>.
> just seen the same issue even in the Maven version of downloaded jars:
> in the 2.0.1 I'll add the (optional if possible) dependency on
> SVGSalamander to WTK.

It is optional - it is only necessary if you want to use a Drawing in your app.


Re: where is com.kitfox.svg.SVGDiagram?

Posted by Sandro Martini <sa...@gmail.com>.
Hi all,
just seen the same issue even in the Maven version of downloaded jars:
in the 2.0.1 I'll add the (optional if possible) dependency on
SVGSalamander to WTK.


And, even the demo.jnlp.xsl (which generates jnlp files for demos) has
to be fixed for references to SVGSalamander wrong inside ... or
better, the generated jnlp file is not working.


As soon as possible I'll add a JIRA ticket for both things (in this
moment our JIRA is down for maintenance) ...

Bye,
Sandro

Re: where is com.kitfox.svg.SVGDiagram?

Posted by Greg Brown <gk...@verizon.net>.
> I tried to display SVG images, but I got a ClassNotFoundException for  com.kitfox.svg.SVGDiagram:
> 
> Caused by: java.lang.NoClassDefFoundError: com/kitfox/svg/SVGCache
>        at org.apache.pivot.wtk.media.SVGDiagramSerializer.readObject(SVGDiagramSerializer.java:43)
>        at org.apache.pivot.wtk.media.Image$LoadTask.execute(Image.java:101)
>        at org.apache.pivot.wtk.media.Image.load(Image.java:144)
>        at org.apache.pivot.wtk.ImageView.setImage(ImageView.java:248)
> 
> Is another jar required beside the binary distribution?

Yes. From the README:

* SVG support requires SVG Salamander, which is licensed under a dual LGPL/BSD
  license and is available here:

  https://svgsalamander.dev.java.net/

G


where is com.kitfox.svg.SVGDiagram?

Posted by anton dos santos <ad...@free.fr>.
Hi
I tried to display SVG images, but I got a ClassNotFoundException for  com.kitfox.svg.SVGDiagram:

Caused by: java.lang.NoClassDefFoundError: com/kitfox/svg/SVGCache
         at org.apache.pivot.wtk.media.SVGDiagramSerializer.readObject(SVGDiagramSerializer.java:43)
         at org.apache.pivot.wtk.media.Image$LoadTask.execute(Image.java:101)
         at org.apache.pivot.wtk.media.Image.load(Image.java:144)
         at org.apache.pivot.wtk.ImageView.setImage(ImageView.java:248)

Is another jar required beside the binary distribution?
Regards
Anton

Re: How parse a JSON to List

Posted by Greg Brown <gk...@verizon.net>.
GSON will work, but Pivot's JSONSerializer class will output Pivot data types such as Sequence and Dictionary that can be used as model data (e.g. to back a list or table view). 

If you want to deserialize JSON into a bean, you just need to pass the bean type to the JSONSerializer constructor.

G

On Jan 27, 2011, at 10:18 PM, Clint Gilbert wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> They're not part of Pivot, but Google Gson and, for Scala, Lift's JSON
> lib[1], can both do this nicely.
> 
> Gson makes use of the gnarly "type-token" idiom to work around type
> erasure when unmarshalling things like List<Bean>, but the gnarliness is
> Java's fault, not Gson's.
> 
> [1] This came out of the Lift webapp framework, but is standalone.
> 
> On 01/27/2011 08:22 PM, Chris Bartlett wrote:
>> Vanio,
>> 
>> Take a look at
>> http://svn.apache.org/repos/asf/pivot/trunk/core/test/org/apache/pivot/json/test/BindTest.java
>> 
>> and the other related JSON test files
>> http://svn.apache.org/repos/asf/pivot/trunk/core/test/org/apache/pivot/json/test/
>> 
>> Chris
>> 
>> On 28 January 2011 07:36, Vanio Meurer <vaninho@gmail.com 
>> <ma...@gmail.com>> wrote:
>> 
>> 
>>    Hello, how I can parse a JSON to List<Bean>?
>>    Or how I can get the List<Bean> with GetQuery?
>>    I really tried a lot of ways, but I don't have success.
>>    --
>>    View this message in context:
>>    http://apache-pivot-users.399431.n3.nabble.com/How-parse-a-JSON-to-List-Bean-tp2364779p2364779.html
>>    Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>> 
>> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> 
> iEYEARECAAYFAk1CNXAACgkQ0GFaTS4nYxsxoQCfaWNcDpyauCDdz2xSWt+b+SWO
> 1BIAoJtgYksuz1BbyhEDoEc2IJAGFIzT
> =8fO3
> -----END PGP SIGNATURE-----


Re: How parse a JSON to List

Posted by Clint Gilbert <cl...@hms.harvard.edu>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

They're not part of Pivot, but Google Gson and, for Scala, Lift's JSON
lib[1], can both do this nicely.

Gson makes use of the gnarly "type-token" idiom to work around type
erasure when unmarshalling things like List<Bean>, but the gnarliness is
Java's fault, not Gson's.

[1] This came out of the Lift webapp framework, but is standalone.

On 01/27/2011 08:22 PM, Chris Bartlett wrote:
> Vanio,
> 
> Take a look at
> http://svn.apache.org/repos/asf/pivot/trunk/core/test/org/apache/pivot/json/test/BindTest.java
> 
> and the other related JSON test files
> http://svn.apache.org/repos/asf/pivot/trunk/core/test/org/apache/pivot/json/test/
> 
> Chris
> 
> On 28 January 2011 07:36, Vanio Meurer <vaninho@gmail.com 
> <ma...@gmail.com>> wrote:
> 
> 
>     Hello, how I can parse a JSON to List<Bean>?
>     Or how I can get the List<Bean> with GetQuery?
>     I really tried a lot of ways, but I don't have success.
>     --
>     View this message in context:
>     http://apache-pivot-users.399431.n3.nabble.com/How-parse-a-JSON-to-List-Bean-tp2364779p2364779.html
>     Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
> 
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk1CNXAACgkQ0GFaTS4nYxsxoQCfaWNcDpyauCDdz2xSWt+b+SWO
1BIAoJtgYksuz1BbyhEDoEc2IJAGFIzT
=8fO3
-----END PGP SIGNATURE-----

Re: How parse a JSON to List

Posted by Vanio Meurer <va...@gmail.com>.
In those tests we don't have anyone testing the java.util.Date class.
It's will work fine too?
I'm getting this exception:

An error occurred while processing input at line number 1
org.apache.pivot.web.QueryException: 500
org.apache.pivot.serialization.SerializationException: Could not determine
sequence item type.
	at org.apache.pivot.web.Query.execute(Query.java:489)
	at org.apache.pivot.web.GetQuery.execute(GetQuery.java:53)
	at org.apache.pivot.util.concurrent.Task$ExecuteCallback.run(Task.java:42)
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.pivot.serialization.SerializationException: Could not
determine sequence item type.
	at
org.apache.pivot.json.JSONSerializer.readListValue(JSONSerializer.java:598)
	at org.apache.pivot.json.JSONSerializer.readValue(JSONSerializer.java:303)
	at org.apache.pivot.json.JSONSerializer.readObject(JSONSerializer.java:273)
	at org.apache.pivot.json.JSONSerializer.readObject(JSONSerializer.java:232)
	at org.apache.pivot.web.Query.execute(Query.java:474)
	... 6 more

Using:
GetQuery get = new GetQuery("localhost", 8888, "/person", false);
get.setSerializer(new JSONSerializer((new
TypeLiteral<java.util.ArrayList<Person>>(){}).getType()));

The JSON is ok:
[{firstName: "Vânio", lastName: "Meurer", dateOfBirth: {date: 5, time:
1294185600000, hours: 0, minutes: 0, month: 0, seconds: 0, year: 111},
foreign: true, id: 1, height: 1.96, weight: 80.0}, {firstName: "Agora",
lastName: "Sim", dateOfBirth: {date: 25, time: 1295913600000, hours: 0,
minutes: 0, month: 0, seconds: 0, year: 111}, foreign: false, id: 2, height:
2.0, weight: 2.0}, {firstName: "Agora Vai", lastName: "Haha", dateOfBirth:
{date: 25, time: 1295913600000, hours: 0, minutes: 0, month: 0, seconds: 0,
year: 111}, foreign: false, id: 3, height: 3.0, weight: 3.0}, {firstName:
"sim", lastName: "sxx", dateOfBirth: {date: 25, time: 1295913600000, hours:
0, minutes: 0, month: 0, seconds: 0, year: 111}, foreign: false, id: 4,
height: 12.0, weight: 12.0}, {firstName: "dsd", lastName: "adasd",
dateOfBirth: {date: 25, time: 1295913600000, hours: 0, minutes: 0, month: 0,
seconds: 0, year: 111}, foreign: false, id: 5, height: 22.0, weight: 2.0},
{firstName: "Giselly", lastName: "Felippe", dateOfBirth: {date: 27, time:
1296086400000, hours: 0, minutes: 0, month: 0, seconds: 0, year: 111},
foreign: false, id: 6, height: 12.0, weight: 11.0}]
-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/How-parse-a-JSON-to-List-Bean-tp2374783p2390132.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: How parse a JSON to List

Posted by Chris Bartlett <cb...@gmail.com>.
Vanio,

Take a look at
http://svn.apache.org/repos/asf/pivot/trunk/core/test/org/apache/pivot/json/test/BindTest.java

and the other related JSON test files
http://svn.apache.org/repos/asf/pivot/trunk/core/test/org/apache/pivot/json/test/

Chris

On 28 January 2011 07:36, Vanio Meurer <va...@gmail.com> wrote:

>
> Hello, how I can parse a JSON to List<Bean>?
> Or how I can get the List<Bean> with GetQuery?
> I really tried a lot of ways, but I don't have success.
> --
> View this message in context:
> http://apache-pivot-users.399431.n3.nabble.com/How-parse-a-JSON-to-List-Bean-tp2364779p2364779.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>