[Building Sakai] EntityBroker and posting JSON

Adrian Fish a.fish at lancaster.ac.uk
Fri Feb 5 06:48:03 PST 2010


I get this from EB ...

{
  "attendeePassword": null,
  "host": null,
  "id": null,
  "joinQuery": null,
  "moderatorPassword": null,
  "name": "Test",
  "participants": [
    {
      "role": "moderator",
      "userId": "xyz-123"
    }
  ],
  "properties": null,
  "reference": "\/bbb-meeting\/\/null",
  "siteId": null,
  "token": "my-meeting-token",
  "url": null,
  "entityReference": "\/bbb-meeting\/dfdf",
  "entityURL": 
"http:\/\/btc224000006.lancs.ac.uk\/direct\/bbb-meeting\/dfdf",
  "entityId": "dfdf"
}

... which is a faithful representation of my POJO.

But when I send this ...

{
  "name":"tree",
  "participants":[
    {
      "userId":"a7b91246-9cb6-44ad-b0fe-e7482244e803",
      "role":"moderator"
     }
    ]
}

.. the data gets serialised back into a POJO, apart from the 
participants. All I get is a String containing '[object Object]' in the 
first element of my List of Participants on my main object.

I'm guessing that it's either jquery not serialising the object out 
properly, or EB doesn't descend into the received object deeply enough.

This is on the trunk as checked out on Tuesday.

Any ideas?

Cheers,

Adrian.

Aaron Zeckoski wrote:
> You do not, however, you will need an empty constructor. It tends to
> work best if you export the entity (GET) as json and then use the same
> structure for the import. The system tries hard to interpret the
> incoming data but adhering to the structure that is returned is the
> safest option.
> -AZ
>
>
> On Fri, Feb 5, 2010 at 11:23 AM, Adrian Fish <a.fish at lancaster.ac.uk> wrote:
>   
>> Hi Lovemore,
>>
>> Thanks a bunch for replying so quickly. Do you have to setup keys in the
>> json for every field in your POJO, even if the values are empty?
>>
>> Cheers,
>>
>> Adrian.
>>
>> Lovemore Nalube wrote:
>>     
>>> Dear Adrian
>>>  Yes it is possible and very easy too!
>>> Your jQuery code seems to work, though you do not need the .json in the
>>> url and the dataType in this case is not necessary as well. A meaningful
>>> error reason will come from xmlHttpRequest.statustext as that will return
>>> the error headers eg: Forbidden (403).
>>>  On the EntityProvider side, you will need to do the following (in this
>>> example SmsAccount is a POJO):
>>> 1. specify a public Object getSampleEntity() that returns new SmsAccount()
>>> 2. in createEntity ensure you have: SmsAccount smsAccount = (SmsAccount)
>>> entity; //entity in this case entity is the createEntity method parameter.
>>> 3. throw appropriate service/validation errors in createEntity so that the
>>> jQuery code can respond appropriately.
>>>  That's it. Make sure the parameter names (ie object keys in jsonData) are
>>> the same as in your POJO definition.
>>>  :)
>>>  --
>>> Lovemore Nalube
>>> Online Learning Environments Developer (Vula)
>>> PASS Transformation Committee REP
>>> Centre for Educational Technology
>>> CHED
>>> University of Cape Town
>>> www.cet.uct.ac.za
>>>
>>> /* Work Email: lovemore.nalube at uct.ac.za
>>> /* Cell: 076 186 1244
>>> /* GTalk: lovenalube at gmail.com
>>>
>>>
>>>       
>>>>>> On 05/02/2010 at 12:47, in message <4B6BF72E.6050702 at lancaster.ac.uk>,
>>>>>> Adrian Fish <a.fish at lancaster.ac.uk> wrote:
>>>>>>             
>>> Can you post  a json string to the EB direct handler and have it decoded
>>> into a POJO? Anybody know ? I was hoping to be able to post JSON to EB
>>> with code like this:
>>>
>>> jQuery.ajax(
>>>        {
>>>            url : "/direct/bbb-meeting/new.json",
>>>            dataType : "text",
>>>            type : 'POST',
>>>            data : jsonData,
>>>            success : function(meeting)
>>>            {
>>>                switchState('currentMeetings');
>>>            },
>>>            error : function(xmlHttpRequest,status,error)
>>>            {
>>>                alert("Failed to create meeting. Reason: " + error);
>>>            }
>>>        });
>>>
>>> ... but am having no success. The entity in my createEntity method is
>>> uninitialised.
>>>
>>> Any ideas? Anyone?
>>>
>>> Thanks,
>>>
>>> Adrian.
>>>
>>> --
>>> ==================================
>>> Adrian Fish
>>> Software Engineer
>>> Centre for e-Science
>>> Bowland Tower South C Floor
>>> Lancaster University
>>> Lancaster
>>> LA1 4YW
>>> email: a.fish at lancaster.ac.uk
>>>
>>> http://confluence.sakaiproject.org/display/YAFT/Yaft
>>> http://confluence.sakaiproject.org/display/BLOG/Home
>>> http://confluence.sakaiproject.org/display/AGORA/Home
>>>
>>>       
>> --
>> ==================================
>> Adrian Fish
>> Software Engineer
>> Centre for e-Science
>> Bowland Tower South C Floor
>> Lancaster University
>> Lancaster
>> LA1 4YW
>> email: a.fish at lancaster.ac.uk
>>
>> http://confluence.sakaiproject.org/display/YAFT/Yaft
>> http://confluence.sakaiproject.org/display/BLOG/Home
>> http://confluence.sakaiproject.org/display/AGORA/Home
>>
>>
>> _______________________________________________
>> sakai-dev mailing list
>> sakai-dev at collab.sakaiproject.org
>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>
>> TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org
>> with a subject of "unsubscribe"
>>
>>     
>
>
>
>   

-- 
==================================
Adrian Fish
Software Engineer
Centre for e-Science
Bowland Tower South C Floor
Lancaster University
Lancaster
LA1 4YW
email: a.fish at lancaster.ac.uk

http://confluence.sakaiproject.org/display/YAFT/Yaft
http://confluence.sakaiproject.org/display/BLOG/Home
http://confluence.sakaiproject.org/display/AGORA/Home

-------------- next part --------------
A non-text attachment was scrubbed...
Name: a_fish.vcf
Type: text/x-vcard
Size: 299 bytes
Desc: not available
Url : http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20100205/55cfe7b0/attachment.vcf 


More information about the sakai-dev mailing list