Custom toJSON() method is not called for each property

I'm getting familiar with JSON in ActionScript 3 (FP 11), and experimenting with custom toJSON methods. The Developer's Guide section on Native JSON Support clearly states:
JSON.stringify() calls toJSON(), if it exists, for each public property that it encounters during its traversal of an object. A property consists of a key-value pair. When stringify() calls toJSON(), it passes in the key, k, of the property that it is currently examining. A typical toJSON() implementation evaluates each property name and returns the desired encoding of its value.
However, both the subsequent examples on the very same page and my own tests indicate that, on the contrary, toJSON() is only called once for the whole object, and no argument is passed for k. Take the following trivial class:
public class JSONTest {
    public var firstProperty:int = 1;
    public var secondProperty:String = "Hello world";
    public function toJSON(k:String):* {
        trace("Calling toJSON on key", k);
        return this[k].toString();
According to the documentation this should cause the following to print:
Calling toJSON on key firstProperty
Calling toJSON on key secondProperty
And the output should basically be the same as without a custom toJSON method:
{ "firstProperty" : 1, "secondProperty" : "Hello world" }
Instead, this just throws an error because nothing at all is passed as k.
So, is the documentation wrong and the engine is not supposed to call toJSON for every property, or is the engine incorrectly only calling it once?

I just figured out what the documentation means. k refers to the name of a property to which the entire instance being stringified is assigned, not to the names of the properties of the instance being stringified. An example is much clearer:
var wrapper:Object = { prop1 : 1, prop2 : new JSONTest() };
trace("Stringify result =", JSON.stringify(wrapper));
Prints:
k:String = prop2
Stringify result = {"prop2":{"firstProperty":1,"secondProperty":"Hello world"},"prop1":1}
So k is the name of the property on wrapper, not on the JSONTest instance. When stringify is called directly on an instance of JSONTest, k is empty because the JSONTest instance is not assigned as a property of another object, it is just all by itself. Either way the value returned by toJSON must be a string or object representing the stringified form of the entire instance.

Similar Messages

  • GET_V Method is not called for custom field

    Hi,
    We are using CRM 7.0
    I have enhanced component BT120H_CPL and added custom fields into view Details with AET. I am trying to implement search help which depends on another field. I have created V-GETTER for my field and tried to implement search help in this method. However, this method is not called in the program scope.
    I have debugged the application and result is :
    V_GETTER method GET_V_ZZAFLD00000D is created in class ZL_BT120H_C_DETAILS_CN00. It should be called from GET_V_S_EXT method but this method is called in class CL_BT120H_C_DETAILS_CN00 and exception occurs since GET_V_ZZAFLD00000D doesnu2019t exist in class CL_BT120H_C_DETAILS_CN00.
    I tried similar scenario : add search help to existing field of another component. However I couldnu2019t able to run GET_V method again.
    ( It works when I write search help id in the AET but in this way I cannot pass import parameter to it )
    Is there anything I am missing ? Thanks in advance for helps.
    Regards
    Abdul.

    Hi,
        Then, the next possible thing is checking the "enhancement set". Press F2 keeping the cursor on any field and check if the view is showing up as enhanced. Find this information under "Active Enhancement set" in the popup details. If this does not happen, then your enhanced view is not being used. You may want to check the COMPONENT_LOADING BADI if you are using more than one assignment set. You may also want to look at this WIKI.
    [http://wiki.sdn.sap.com/wiki/display/CRM/HowToEnhanceaWebUIComponentinSAP+CRM]
    Regards,
    Arun Prakash

  • Decode not called for all UIComponents in tree

    Many of the faces .jsp pages I have been working with in EA2 have not been updating their models properly.
    The symptom I have observed is that the decode method is not called for all of the UIComponents on the page.
    I think I have tracked this down to a bug in the class com.sun.faces.tree.TreeNavigatorImpl. This class appears to be used internally by some of the .jsf code to navigate the component tree.
    Studying various stack traces, it looks like the method TreeNavigatorImpl.getNextStart() is supposed to provide a preorder traversal of the component tree. Starting from the root of the tree, each call is expected to return the next node. Experimental evidence suggests that it is not doing that properly, and it fails to visit all the nodes in the tree.
    For example, if my component tree looks like this (this is a representation of the tree; not an example of a .jsp page):
    <node id = "/">
       <node id = "page">
          <node id = "carStoreForm">
             <node id = "ba0">
                 <node id = "ba1">
                     <node id = "ba3"/>
                     <node id = "br4"/>
                 </node>
             </node>
             <node id = "bold1"/>
             <node id = "more1"/>
          </node>
       </node>
    </node>A preorder traversal of these nodes should visit nodes:
    '/page'
    '/page/carStoreForm'
    '/page/carStoreForm/ba0'
    '/page/carStoreForm/ba0/ba1'
    '/page/carStoreForm/ba0/ba1/ba3'
    '/page/carStoreForm/ba0/ba1/br4'
    '/page/carStoreForm/bold1'
    '/page/carStoreForm/more1'
    However, when I write test code that calls TreeNavigatorImpl.getNextStart() directly, only the following nodes are returned:
    '/page'
    '/page/carStoreForm'
    '/page/carStoreForm/ba0'
    '/page/carStoreForm/ba0/ba1'
    '/page/carStoreForm/ba0/ba1/ba3'
    '/page/carStoreForm/ba0/ba1/br4'
    It looks to me like the method loses track of the state of the traversal, and prematurely returns null before all the nodes are visited. (It is failing to return the "bold1" and "more1" nodes.)
    This is all extremely speculative. Without jsf source or doc for any of the tree classes, it is difficult to know what is supposed to be going on. And, of course, I may just have a bug in my code.

    Okay, rather than wait for Max to respond, I decompiled the TreeNavigatorImpl class myself and studied the source code. The
    problem arises in the getNextStart() method. If the method returns
    a null value, then presumably the class has successfully traversed
    the entire tree in preorder. Unfortunately, there was a slight
    logic error that would halt traversal after you got to the last node
    of the last subtree at the beginning of your travels.
    The following code should correct this situation (let me know if I've
    introduced any new problems into the mix...). I tested this out using the simple example that Max describes above. The test code appears at the end of my revised method:
    public UIComponent getNextStart() {
    UIComponent cur = null;
    if (startTraversalDone) {
    return cur;
    if (startStack.empty()) {
    cur = root;
    Iterator iter = cur.getChildren();
    if (iter.hasNext()) {
    startStack.push(iter);
    else {
    while (!startStack.empty()) {
         Iterator iter = (Iterator) startStack.peek();
         if (iter != null && iter.hasNext()) {
         cur = (UIComponent) iter.next();
         Iterator childIter = cur.getChildren();
         if (childIter != null && childIter.hasNext()) {
         startStack.push(childIter);
         else {
         if (!iter.hasNext()) {
         startStack.pop();
         break;
    else {
         startStack.pop();
    if (startStack.empty()) {
    startTraversalDone = true;
    if (cur != null) {
    endStack.push(cur);
    return cur;
         public static void main(String[] args) {
              MyComp root = new MyComp("root");
              // build tree....
              MyComp page = new MyComp("page");
              root.addChild(page);
              MyComp csf = new MyComp("csf");
              page.addChild(csf);
              MyComp ba0 = new MyComp("ba0");
              csf.addChild(ba0);
              csf.addChild(new MyComp("bold1"));
              csf.addChild(new MyComp("more1"));
              MyComp ba1 = new MyComp("ba1");
              ba0.addChild(ba1);
              ba1.addChild(new MyComp("ba3"));
              ba1.addChild(new MyComp("ba4"));
              MyTreeNavigator nav = new MyTreeNavigator(root);
              MyComp comp = null;
              while ((comp = (MyComp) nav.getNextStart()) != null) {
                   System.out.println(comp.getComponentId());
    public class MyComp extends UIComponentBase {
         public MyComp(String id) {
              this.setComponentId(id);
         public String getComponentType() {
              return "MyComp";

  • P and V Getter not called for custom attributes!

    Hi,
    i implemented a new search structure instead of CRMST_QUERY_SLSORD_BTIL for business transaction search.
    I enhanced the new structure with a custom field and generated v and p-getter methods to have a dropdown listbox.
    Unfortunately the p and v getter are not called by the framework.
    The field in the context node is STRUCT./SEW/BILLINGBLOCK.
    I have no idea why this methods are not called by the framework.
    br
    Jürgen

    For the advanced search you do not have to implement a V getter. Instead, you must
    redefine method GET_DQUERY_DEFINITIONS in the implementation class of the view
    controller.

  • Region Monitoring iOS 7 : didEnterRegion method is not calling when app is killed by user or by OS in iOS 7 only. It is working fine when it is in background. and the same code is working fine with iOS 6 for both app in suspended mode and background mode.

    Region Monitoring iOS 7 : didEnterRegion method is not calling when app is killed by user or by OS in iOS 7 only. It is working fine when it is in background. and the same code is working fine with iOS 6 for both app in suspended mode and background mode. What changes I have to made to work great in iOS 7 also.

    I rewrote code for debugging purpose and tried to catch error using GetLastError();  method,
    but it only printed 0. Below is code snippet; I think Create() throw an exception
    and code goes to catch block. 
    LONG ConnectTS(CString strIP, UINT n_Port)
    try{
              ErrorLog(0,0,"ConnectTS is calling Create [is going to call]","");
              if(!Create())
    // Exception Line
    n_Err = GetLastError();
    return NET_INIT;
    catch(...)
                       DWORD errorCode = GetLastError();
                       CString errorMessage
                       errorMessage.Format("%lu",errorCode);
                       ErrorLog (0, 0, "Image
    System", (LPTSTR)(LPCTSTR)errorMessage);
                       return  IS_ERR_WINDOWS;
    Output: -
    ConnectTS is calling Create [is going to call]
    Image System
    0

  • Parse method is not possible for this type

    I have a file upload component and one button in a view.
    I have created a binary type context element and mapped it with fileupload component.while clicking the submit button I am getting " Parse method is not possible for this type" exception.
    help me out.
    Thanks In advance

    Hi,
    Thanks for your response. I have written the following code in wddoinit():     
    IWDAttributeInfo attributeinfo = wdContext.getNodeInfo().getAttribute(IPrivateSubstanceDocView.IFileUpload02Element.DATA);
        attributeinfo.getModifiableSimpleType();
    fileUpload02 is my context.
    but I am getting a null pointer exception over here.
    can ypu please help it.
    Actually the case is this is a window, which is opening on click of a hyperlink on another View.
    With the action method I am calling this View.
    Thus on click of a hyperlink just I am opening a new  View then here I am a browse button etc...
    PLease help if you can

  • Method SAP_WAPI_WORKITEM_COMPLETE not allowed for type F

    Hi Gurus
    I have created a webdynpro abap application in which these steps
    1. Application triggers the workflow and workitem got created through FM1.
    2. Workitem loads up webdynpro abap application from portal or outlook by changing settings in SWFVISU transaction.
    3. Application completes the workflow by calling FM2.
    Here FM1 is SAP_WAPI_START_WORKFLOW which returns the workitem id. When I am giving the same workitem id in function module SAP_WAPI_WORKITEM_COMPLETE , it is giving me error that Method SAP_WAPI_WORKITEM_COMPLETE not allowed for type F
    My workflow has only one activity step which is mapped with class CL_PT_REQ_WF_ATTRIBS and method DUMMY. I have checked the synchronous method.
    Please let me know how can I correct it.
    With regards
    Manu Sharma

    Hi
    You need to give the workitem id of the dialog task which has been configured in SWFVISU. You will get this workitem id via application parameter in your Webdynpro method.
    Wokflow will be completed, if all the steps has been executed
    Vinoth
    Edited by: S Vinoth on Oct 27, 2010 10:08 AM

  • CreateRowFromResultSet not called for first row

    Hi all,
    Jdev Version: 11.1.1.7.0
    I have an XML stored in DB as  a CLOB. I fetch this XML as a CLOB (using clobdomain) in my VO and need to populate a few other transient attributes. I attempted to achieve this by overriding (as per blog entry) method 'createRowFromResultSet'. I observe a weird behaviour where this method does not get invoked for the first row alone.
    A while back, I see another member suffer from a similar issue - forum thread. Is this a bug that appears when using clob and overriding this method?
    Thanks in advance,
    Srini

    Hi,
    we have the same problem. The method createRowFromResultSet() is not called for the first row. We don't have a CLOB. We have a primary key of type Raw. Maybe this is causing the problem.
    We are using JDev 11.1.1.6.
    Regards,
    Linda

  • @PostConstruct method is not called in weblogic 12.1.2 server

    Dear all,
    Currently, i'm using jsf 2 application and it's deployed in weblogic 12.1.2 server.
    The issue is : the @PostConstruct method is not called.
    I tried to search and know that: this one is fixed by a patch of weblogic 12.1.1 server.
    Patch 13703600: SU Patch [UXPH]: WLS12C - POSTCONSTRUCT NOT CALLED ON @MANAGEDBEAN BEANS IN JSF APP
    Last Updated 29-Feb-2012 03:03 (1+ year ago)
    Product Oracle WebLogic Server
    Release WLS 12.1.1.0
    So why does this happen again in weblogic 12.1.2 server? Or may i miss something?
    Did someone have experience about this issue?
    Thank you so much for your help.
    Best regards.

    Hi,
    I can see that bug 13703600 is already got fixed in 12.1.2 but still you same problem please raise ticket with oracle support.
    Regrds,
    Kal

  • Adobe Offline Form - Parse method is not possible for this type

    Hi All,
    I have developed an application for the offline scenario of interactive adobe form. I tried to load the adobe form from my desktop. After pressing the button "Display form" it throws an error "Parse method is not possible for this type".
    If I include wdContext.getNodeInfo().getAttribute("pdfObject").getModifiableSimpleType() in the doInit() method of the view I receive this error -
    com.sap.tc.webdynpro.progmodel.context.ContextException: MappedAttributeInfo(UploadView.pdfObject): must not modify the datatype of a mapped attribute
    When I comment it out and upload I receive the error enclosed -
    Parse method is not possible for this type
    Can someone please help me with a step by step solution to this problem?
    Any help is highly appreciated.
    Many thanks,
    Divya

    Hi Divya,
    Please try to do it as stated below:
         IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute("pdfObject");
         ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();
         IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType)type;
    Try putting the code in wdInit() or wdDoModifyView().
    Let me know if you still face the issue.
    Regards,
    Arafat

  • Parse method is not possible for this type Exception in web dynpro

    I have a file upload component and one button in a view.
    I have created a binary type context element and mapped it with fileupload component.while clicking the submit button I am getting " Parse method is not possible for this type" exception.
    help me out.

    Hi sridhar,
    Use this code for Upload
    context u create one attribute(up),u assign the data type as "Resource"(which is dictionary type)
    InputStream text = null;
        int temp = 0;
        try
             File file = new File(wdContext.currentContextElement().getUp().getResourceName());
             FileOutputStream op = new FileOutputStream(file);
             if(wdContext.currentContextElement().getUp()!=null)
                  text = wdContext.currentContextElement().getUp().read(false);
                   while((temp=text.read())!=-1)
                                                                       op.write(temp);
             op.flush();
             op.close();
        catch(Exception e)
         e.printStackTrace();   

  • Multiple web service calls - Split message,1 WS call for each message

    Friends,
    We have designed a BPM which will pick the files, make web service call and merge these message structures and map them to the target.
    We have to modify this design as follows,
    We have to split the message based on purchase order number, meaning one message for each order number and then we need to make a web service call for each of them,after we get all the responses we will merge the files using transformation. (merging files and transformation is already taken care, its the web service part which iam looking for)
    Thanks in advance for all your help/ideas.

    Friends,
    Can you please help me out with this logic? Thanks!

  • Drawing with a custom profile stroke is not working for me. Does it work for you?

    Drawing with a custom profile stroke is not working for me. Does it work for you?
    I can only apply it on an existing stroke but can't draw a new one with the selected profile. In fact if I change the profile to other than the default Uniform I also can't draw a new stroke with any other width than the default 1 point. This doesn't seem normal.
    Using SC5 on a PC.

    Another question on the same topic.
    Once I add a new profile to the list is it possible to put it on top of the list. I need this because the Adobe people decided to put the list in a tiny scrollable window with only a few of the first profiles showing. If there is noting in the interface may be I have to modify some program files settings?

  • Method "equals" not implemented for class "Pan1"

    Method "equals" not implemented for class "Pan1" -- this is the error I'm getting while running one static Analyzer. Can anybody say, what is this error , and how to rectify it ?

    The static analyzer may have noticed that either you may invoke .equals() on instances of this class (possibly through polymorphism) and you have not implemented the method in your class. This is most likely a warning since many times lack of an implemented .equals() method in such cicumstances will lead to Object.equals() being executed and that simply checks to see if the object references are the same - quite a bit stronger than what one would probably expect from .equals();
    it is also possible that you did implement an equals() method but that you used the wrong argument type. This is a common mistake:
    public boolean equals(MyClass other) {
       return /* something */;
    }This type of warning may be ignored, or if it troubles you and there is no way to disable it for the classes that you know you have implemented correctly, you might consider adding an equals method of the form:
    public boolean equals(Object other) {
       return super.equals(other);
    }Chuck

  • HT201407 I backed up my phone before it was replaced.  My apps have disappeared altogether, and my music is there but it indicates that I need to download (not pay for) each track again.  What have I missed?

    I backed up my phone before it was replaced.  My apps have disappeared altogether, and my music is there but it indicates that I need to download (not pay for) each track again. It's only small stuff, but my ringtones and photos and background etc have all gone, too.  What have I missed?

    How to BackUp  >  http://support.apple.com/kb/ht1766
    What gets Backed Up
    iTunes http://support.apple.com/kb/ht4946
    iCloud http://support.apple.com/kb/PH2584
    Restore from Backup  >  http://support.apple.com/kb/ht1766

Maybe you are looking for

  • Sharing a computer with different user/accounts libraries

    Is it possible to use my parents MacBook iTunes in the Netherlands to open a new Library and associate that with my own US account so I can synchronize my iPhone and iPod with my stuff? That would spare me dragging along our Macbook every time but I

  • How do I stop Windows 7 from searching hidden files and folders

    In XP it was simple with the intuitive Advanced Search Options. Even if you enable "Don't show Hidden Files and Folders" in Windows 7, they still show up in the search menu.  A similar post included a suggestion by a support dude to post a question h

  • HVR A1U

    My name is Brian and I am an intern with the U.S. Fish and Wildlife Service in Oklahoma. We are doing a population survey of the Ozark big-eared bat using infrared cameras and lights. We are using the HVR A1U with external lighting to video the bats

  • Deleated downloads stack

    i accidently dragged my downloads stack to the trash and i cannot get it to reopen from the trash onto the dock. Does anyone know how to create a new internet plug-in stack? or how to reopen it from the trash?

  • Blue/Grey screen on start

    After Herd Drive replacement and reinstalling programmes from Time Capsul, on start up I get first a grey screen and then a blue screen for some time after which the system runs normally. Before the hard drive was replaced the system started up much