You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tom McLaughlin <to...@gmail.com> on 2008/09/04 21:57:55 UTC
JSON and RPC without JSON-RPC
Hi All,
I've got a javascript front-end that makes asynchronous requests to perform
various CRUD operations. Ideally, I'd like to write an Action and expose it
directly to my client using JSONUtils to serialize and deserialize my
objects. The JSON plugin gets me close, but I don't like having to expose
data as a side-effect of calling my Action's methods. For example,
presently I might have an Action that looks like this...
class PersonAction {
@Inject...
PersonDAO dao;
Person person;
String id;
public String create(){
person = dao.create(person);
return SUCCESS.
}
public String retrieve(){
dao.load(id);
}
//getters and setters for person and id go here
}
But I'd rather have an Action that looks like this...
class PersonAction {
@Inject...
PersonDAO dao;
public void create(Person person){
dao.create(person);
}
public Person retrieve(String id) {
return dao.load(id);
}
...
}
Person would be an entity class, e.g.
class Person {
String firstName;
String lastName;
//getters and setters for firstName and lastName go here...
}
The SMD annotations in the JSON plugin come close, but I'd like to go the
extra step and not be confined to my client sending "method", "id", and
"params" parameters. So in the above example I'd post to
/person!create.action with JSON like {firstName : 'Theodore',
lastName:'Koppel'}, i.e. the JSON analogue of my "Person" object.
Has anyone tried anything like this? I've started looking at creating the
Interceptor and Result classes to support this, but I'd like to know if
other folks are doing similar things and if what I'm seeking to do is even
possible, knowing I'll likely have to develop a plugin to support the idea.
Any thoughts?
Thanks,
Tom
Re: JSON and RPC without JSON-RPC
Posted by Musachy Barroso <mu...@gmail.com>.
That would be closer to RPC, but would be less "strutish", I think you could
easily extend the JSON plugin to accomplish this.
musachy
On Thu, Sep 4, 2008 at 3:57 PM, Tom McLaughlin <to...@gmail.com>wrote:
> Hi All,
>
> I've got a javascript front-end that makes asynchronous requests to perform
> various CRUD operations. Ideally, I'd like to write an Action and expose
> it
> directly to my client using JSONUtils to serialize and deserialize my
> objects. The JSON plugin gets me close, but I don't like having to expose
> data as a side-effect of calling my Action's methods. For example,
> presently I might have an Action that looks like this...
>
> class PersonAction {
> @Inject...
> PersonDAO dao;
>
> Person person;
> String id;
>
> public String create(){
> person = dao.create(person);
> return SUCCESS.
> }
>
> public String retrieve(){
> dao.load(id);
> }
>
> //getters and setters for person and id go here
>
> }
>
> But I'd rather have an Action that looks like this...
>
> class PersonAction {
> @Inject...
> PersonDAO dao;
>
> public void create(Person person){
> dao.create(person);
> }
> public Person retrieve(String id) {
> return dao.load(id);
> }
> ...
> }
>
> Person would be an entity class, e.g.
>
> class Person {
> String firstName;
> String lastName;
> //getters and setters for firstName and lastName go here...
> }
>
> The SMD annotations in the JSON plugin come close, but I'd like to go the
> extra step and not be confined to my client sending "method", "id", and
> "params" parameters. So in the above example I'd post to
> /person!create.action with JSON like {firstName : 'Theodore',
> lastName:'Koppel'}, i.e. the JSON analogue of my "Person" object.
>
> Has anyone tried anything like this? I've started looking at creating the
> Interceptor and Result classes to support this, but I'd like to know if
> other folks are doing similar things and if what I'm seeking to do is even
> possible, knowing I'll likely have to develop a plugin to support the idea.
> Any thoughts?
>
> Thanks,
> Tom
>
--
"Hey you! Would you help me to carry the stone?" Pink Floyd