Discussion:
Question about types
András Csányi
2012-01-10 20:51:30 UTC
Permalink
Dear All,

This is my first letter for this list, so greetings for everybody! :)
A few weeks ago I met this technology, I mean REST, and I like it very
much! I started to work with resteasy from JBOSS team but
unfortunately I found it too under-documented - I'm a weekend
programmer because I'm a testing engineer originally - and I turned
here. Long story short. I have a swing application which get data via
REST. The rest interface at the server side get a List<EntityDTO>
datatype. My question is that whether Jersey is able to handle this
datatype using JSON protocol? The client is able to deserialize it?
I've read a few articles about json deserialize issue regarding
datatypes.

My other question is that, what is the proper way to handle this
datatype. If it is not possible than what would be the proper datatype
in this case? It would be perfect for me if I get some blog entries
because I like to learn by that way. I use EJB3.1, Beans and REST.

Thank you very much in advance!

András
--
- -
--  Csanyi Andras (Sayusi Ando)  -- http://sayusi.hu --
http://facebook.com/andras.csanyi
--  ""Trust in God and keep your gunpowder dry!" - Cromwell
John Yeary
2012-01-11 01:22:58 UTC
Permalink
Hello András,

I have examples on my blog http://javaevangelist.blogspot.com as well as,
links to some articles. The examples have various examples of using JSON,
and JSONP including with a database with JPA.

Your question is fairly general, but I think that you should be able to
handle it fairly easily if you have the entities in a library jar which can
be shared between the server and client. The jersey.java.net site has good
documentation. I would also suggest downloading the source code, which
includes a number of examples, and contributed examples.

John
____________________________

John Yeary
____________________________

<http://javaevangelist.blogspot.com/> <https://twitter.com/jyeary>
<http://www.youtube.com/johnyeary>
<http://www.linkedin.com/in/jyeary>
<https://plus.google.com/112146428878473069965>
<http://www.facebook.com/jyeary>
<http://feeds.feedburner.com/JavaEvangelistJohnYearysBlog>
<http://netbeans.org/people/84414-jyeary>
____________________________

"Far better it is to dare mighty things, to win glorious triumphs, even
though checkered by failure, than to take rank with those poor spirits who
neither enjoy much nor suffer much, because they live in the gray twilight
that knows not victory nor defeat."
-- Theodore Roosevelt
Post by András Csányi
Dear All,
This is my first letter for this list, so greetings for everybody! :)
A few weeks ago I met this technology, I mean REST, and I like it very
much! I started to work with resteasy from JBOSS team but
unfortunately I found it too under-documented - I'm a weekend
programmer because I'm a testing engineer originally - and I turned
here. Long story short. I have a swing application which get data via
REST. The rest interface at the server side get a List<EntityDTO>
datatype. My question is that whether Jersey is able to handle this
datatype using JSON protocol? The client is able to deserialize it?
I've read a few articles about json deserialize issue regarding
datatypes.
My other question is that, what is the proper way to handle this
datatype. If it is not possible than what would be the proper datatype
in this case? It would be perfect for me if I get some blog entries
because I like to learn by that way. I use EJB3.1, Beans and REST.
Thank you very much in advance!
András
--
- -
-- Csanyi Andras (Sayusi Ando) -- http://sayusi.hu --
http://facebook.com/andras.csanyi
-- ""Trust in God and keep your gunpowder dry!" - Cromwell
András Csányi
2012-01-11 10:15:26 UTC
Permalink
Hello András,
I have examples on my blog http://javaevangelist.blogspot.com as well as, links to some articles.
The examples have various examples of using JSON, and JSONP including with a database with JPA.
Your question is fairly general, but I think that you should be able to handle it fairly easily if you have the entities in a library jar
which can be shared between the server and client. The jersey.java.net site has good documentation. I would also suggest
downloading the source code, which includes a number of examples, and contributed examples.
John
Hi John,

Thank you for your answer! I'm reading the different documentation and
I have a notion about my issue. I have to create a class to wrap my
datatype, do I understand correctly?
I've read that there is not possible to use generic type in this case.
I mean, for example List<EntityDTO>.class, to set up in in response.
So, I think that I create an object called
RESTEntityResponse and this class will contain my desired
List<EntityDTO>. Is it correct by this way?

By the way, my EntityDTO are shared in a particular library between
server and client.

Thanks in advance!

András


--
- -
--  Csanyi Andras (Sayusi Ando)  -- http://sayusi.hu --
http://facebook.com/andras.csanyi
--  ""Trust in God and keep your gunpowder dry!" - Cromwell
John Yeary
2012-01-11 12:37:45 UTC
Permalink
Hello András,

I am not sure what you were looking at, but I would use the
GenericEntity<T> to wrap your class if necessary. It would look something
like

return new GenericEntity<List<EntityDAO>>( YOUR_LIST_VARIABLE_HERE ){};
____________________________

John Yeary
____________________________

<http://javaevangelist.blogspot.com/> <https://twitter.com/jyeary>
<http://www.youtube.com/johnyeary>
<http://www.linkedin.com/in/jyeary>
<https://plus.google.com/112146428878473069965>
<http://www.facebook.com/jyeary>
<http://feeds.feedburner.com/JavaEvangelistJohnYearysBlog>
<http://netbeans.org/people/84414-jyeary>
____________________________

"Far better it is to dare mighty things, to win glorious triumphs, even
though checkered by failure, than to take rank with those poor spirits who
neither enjoy much nor suffer much, because they live in the gray twilight
that knows not victory nor defeat."
-- Theodore Roosevelt
Post by John Yeary
Hello András,
I have examples on my blog http://javaevangelist.blogspot.com as well
as, links to some articles.
Post by John Yeary
The examples have various examples of using JSON, and JSONP including
with a database with JPA.
Post by John Yeary
Your question is fairly general, but I think that you should be able to
handle it fairly easily if you have the entities in a library jar
Post by John Yeary
which can be shared between the server and client. The jersey.java.netsite has good documentation. I would also suggest
downloading the source code, which includes a number of examples, and
contributed examples.
Post by John Yeary
John
Hi John,
Thank you for your answer! I'm reading the different documentation and
I have a notion about my issue. I have to create a class to wrap my
datatype, do I understand correctly?
I've read that there is not possible to use generic type in this case.
I mean, for example List<EntityDTO>.class, to set up in in response.
So, I think that I create an object called
RESTEntityResponse and this class will contain my desired
List<EntityDTO>. Is it correct by this way?
By the way, my EntityDTO are shared in a particular library between
server and client.
Thanks in advance!
András
--
- -
-- Csanyi Andras (Sayusi Ando) -- http://sayusi.hu --
http://facebook.com/andras.csanyi
-- ""Trust in God and keep your gunpowder dry!" - Cromwell
Loading...