Below is a the running sample with filterWithAttributes and 
filterWithAllRecursive()

public WOActionResults testAction() throws Throwable {
        ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes();
        NSMutableDictionary<String, Object> dict = new 
NSMutableDictionary<String, Object>();
        dict.put("x", 1);
        dict.put("data", new NSDictionary<String, Object>(2, "y"));
        return response(dict, filter);
}

HTTP/1.1 200 Apple
Date: Fri, 15 Jul 2011 20:50:10 GMT
Server: Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8r DAV/2 PHP/5.3.4
Cache-Control: max-age=604800
Content-Length: 8
Content-Type: application/json
Connection: close

{"x":1}

public WOActionResults testAction() throws Throwable {
        ERXKeyFilter filter = ERXKeyFilter.filterWithAllRecursive();
        NSMutableDictionary<String, Object> dict = new 
NSMutableDictionary<String, Object>();
        dict.put("x", 1);
        dict.put("data", new NSDictionary<String, Object>(2, "y"));
        return response(dict, filter);
}

HTTP/1.1 200 Apple
Date: Fri, 15 Jul 2011 20:51:35 GMT
Server: Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8r DAV/2 PHP/5.3.4
Cache-Control: max-age=604800
Content-Length: 23
Content-Type: application/json
Connection: close

{"x":1,"data":{"y":2}}


On 2011-07-15, at 11:12 PM, Elizabeth Lynch wrote:

> Hi
> 
>> That should work. What key filter are you using? Are you not allowing keys 
>> in from the nested dictionary?
> 
> Here is my implementation of data for testing (from Category.java):
> 
>       public NSDictionary data() { 
>               return new NSDictionary("key", "stringValue");
>       }
> 
> and  my showFilter (from CategoryController.java):
> 
>       public static ERXKeyFilter showFilter() {
>               ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes();
>               filter.include(new ERXKey<NSDictionary<String,String>>("data"));
>               return filter;
>       }
> 
> results in:
> 
> "data":{"nil":true}
> I assume this is the result of something incredibly obvious that I have 
> overlooked :-).
> 
> Liz
> 
> 
>> 
>> On Jul 15, 2011, at 1:43 PM, Elizabeth Lynch wrote:
>> 
>>> Hi
>>> 
>>>> I think you can define an additional getter method over data as 
>>>> dataDictionary() which should return the data xml as NSDictionary. This 
>>>> will solve the problem for both XML and JSON.
>>> 
>>> Unfortunately that isn't working for me.  Here's some more information I've 
>>> discovered about the ERREST problem; it looks like it can't cope with 
>>> Collections (List/Map, or ArrayList/HashMap). Perhaps it wants nasty beans? 
>>>  Below is an example showing it not coping with a dictionary.
>>> 
>>> 'data' is a derived attribute, returning a dictionary, declared as 
>>> ERXKey<Object> in the ERXKeyFilter (or NSDictionary), it returns:
>>> 
>>>     "data":{"nil":true}
>>> 
>>> An NSArray returns:
>>> 
>>>     "data":["stringValue"]}
>>> 
>>> which is much better.  But an array of dictionary gives:
>>> 
>>>     "data":[{"nil":true}]}
>>> 
>>> So it seems that the JSON converter is having issues with 
>>> NSDictionary/Hashmap (I've tried both).
>>> 
>>> Does anyone have any ideas?
>>> 
>>> Liz
>>> 
>>>> 
>>>> Farrukh
>>>> 
>>>> On 2011-07-15, at 7:24 PM, Elizabeth Lynch wrote:
>>>> 
>>>>> Hi Farrukh
>>>>> 
>>>>> Thanks: that's a good suggestion, but I need to get it into JSON before 
>>>>> it leaves the server, so that technique won't work for me.
>>>>> 
>>>>> Liz
>>>>> 
>>>>> On 15 Jul 2011, at 15:55, Farrukh Ijaz wrote:
>>>>> 
>>>>>> Hi Liz,
>>>>>> 
>>>>>> That's a common issue. Suppose you receive the JSON mentioned below, 
>>>>>> once you get the value of data attribute which is a JSON object in 
>>>>>> string format, evaluate it using eval() method of javascript and it will 
>>>>>> be converted to JSON.
>>>>>> 
>>>>>> Farrukh
>>>>>> 
>>>>>> Sent from my iPad 2
>>>>>> 
>>>>>> On 2011-07-15, at 3:58 PM, Elizabeth Lynch <[email protected]> wrote:
>>>>>> 
>>>>>>> Hi Pascal
>>>>>>> 
>>>>>>> Sorry, I didn't explain the problem clearly.  I am doing that already. 
>>>>>>> The problem is that it comes as a string in my JSON output, not as an 
>>>>>>> object. 
>>>>>>> 
>>>>>>> Liz
>>>>>>> 
>>>>>>> Sent from my iPhone
>>>>>>> 
>>>>>>> On 15 Jul 2011, at 12:39, Pascal Robert <[email protected]> wrote:
>>>>>>> 
>>>>>>>> I think the best way would be to transform the XML to a Java object 
>>>>>>>> and transform that object back to JSON.
>>>>>>>> 
>>>>>>>>> I am building an ERRest application (read only), and am having a 
>>>>>>>>> problem with one field.  This field holds an xml string, which I need 
>>>>>>>>> to embed into the output from show and index actions; it will be 
>>>>>>>>> consumed as json (mainly; possibly only).
>>>>>>>>> 
>>>>>>>>> For example, I would like to receive:
>>>>>>>>> 
>>>>>>>>> {"name" : "A Record", "data" : { "fieldA" : "valueA", "fieldB" : 
>>>>>>>>> "valueB" } }
>>>>>>>>> 
>>>>>>>>> where the data attribute comes from:
>>>>>>>>> 
>>>>>>>>> <SomeElement FieldA="valueA"><FieldB>valueB</FieldB></SomeElement>
>>>>>>>>> 
>>>>>>>>> Or something similar to that.  I can use net.sf.json to do the 
>>>>>>>>> conversion directly, which produces satisfactory strings, but that 
>>>>>>>>> doesn't cope with the XML output format case, and I can't figure out 
>>>>>>>>> how to pass it into my JSON output.  If I do that with a String 
>>>>>>>>> field, then obviously it is output as a string value, not as a JSON 
>>>>>>>>> object, which isn't what I want.
>>>>>>>>> 
>>>>>>>>> In short, the XML is a moderately complex object, which I need to 
>>>>>>>>> output as an object in the JSON format.
>>>>>>>>> 
>>>>>>>>> All ideas appreciated.
>>>>>>>>> 
>>>>>>>>> Liz _______________________________________________
>>>>>>>>> Do not post admin requests to the list. They will be ignored.
>>>>>>>>> Webobjects-dev mailing list      ([email protected])
>>>>>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>>>>> http://lists.apple.com/mailman/options/webobjects-dev/probert%40macti.ca
>>>>>>>>> 
>>>>>>>>> This email sent to [email protected]
>>>>>>>> 
>>>>>>> _______________________________________________
>>>>>>> Do not post admin requests to the list. They will be ignored.
>>>>>>> Webobjects-dev mailing list      ([email protected])
>>>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>>> http://lists.apple.com/mailman/options/webobjects-dev/farrukh.ijaz%40fuegodigitalmedia.com
>>>>>>> 
>>>>>>> This email sent to [email protected]
>>>>> 
>>>> 
>>> 
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Webobjects-dev mailing list      ([email protected])
>>> Help/Unsubscribe/Update your Subscription:
>>> http://lists.apple.com/mailman/options/webobjects-dev/mschrag%40pobox.com
>>> 
>>> This email sent to [email protected]
>> 
> 

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to