Spec-Zone.ru › ColdFusion

structSetMetadata

Sets metadata for a key in a struct. When you want to SerializeJSON, the key and the value will be display as you defined in the metadata.

structSetMetadata(inputStruct, metaStruct) → returns void

Member Function Syntax

inputStruct.setMetadata(metaStruct)

This function requires Adobe ColdFusion 2016.0.2 and up. Not supported on Lucee, etc.
  • CF2016.0.2+
  • See Also: arraySetMetadata arrayGetMetadata structGetMetadata

    Argument Reference

    inputStruct struct
    Required

    The struct in which you want to add the metadata.

    metaStruct struct
    Required

    The metadata struct you want to add.

    Examples
    Sample code invoking the structSetMetadata function

    Add metadata to a struct

    Add metadata to a struct and serialize to a json.It is changing the keyname and convert a string ("20") to a number.

    testStruct = structNew("ordered");
    testStruct.testdata = "example";
    testStruct.testdata2 = "20";
    metadata = {
        testdata: {type: "string", name: "td1" },
        testdata2: {type: "numeric", name: "td2" }
    };
    StructSetMetadata(testStruct,metadata);
    writeoutput(SerializeJSON(testStruct));

    Expected Result: {"td1":"example", "td2":20.0}

    Add metadata to a struct as a member function

    Add metadata to a struct and serialize to a json.It is changing the keyname and convert a string ("20") to a number.

    testStruct = structNew("ordered");
    testStruct.testdata = "example";
    testStruct.testdata2 = "20";
    metadata = {
        testdata: {type: "string", name: "td1" },
        testdata2: {type: "numeric", name: "td2" }
    };
    testStruct.setMetadata(metadata);
    writeoutput(SerializeJSON(testStruct));

    Expected Result: {"td1":"example", "td2":20.0}

    © 2012–present Foundeo, Inc. and the CFDocs contributors.
    Licensed under the MIT License.
    ColdFusion is a trademark of Adobe Systems Incorporated.
    https://cfdocs.org/structsetmetadata

    Spec-Zone.ru

    Настройки Оффлайн Что нового Помощь О нас
    Spec-Zone .ru
    спецификации, руководства, описания, API