3

こんにちは、REST エンドポイントの 1 つから CFC の配列をシリアル化しようとしています。私はこの例を見つけました: アドビヘルプでCFCシリアライゼーションの配列returnType="myCFC[]"

"メッセージ":"配列要素の型が一致しません"

奇妙なことに、同じオブジェクトをインスタンス化して .cfm ファイルからメソッドを呼び出すと、cfdump にはデータを含むオブジェクトの配列が期待どおりに表示されます。しかし、私の AJAX 呼び出しから、オブジェクトのプロパティ値はすべて null です。ただし、 return を使用するとserializeJSON(myArrayOfCFCs)、プロパティにデータが含まれます。しかし、コンテンツ ネゴシエーションの使用が無効になるため、そうする必要はありません。

誰かがこれを機能させているかどうかだけに興味があります。

アップデート:

 <cffunction name="getPatient" access="remote" httpmethod="GET" returntype="Patient[]" produces="text/json" restpath="/{PatientId}">
    <cfargument name="PatientId" type="numeric" required="true" restargsource="Path" />

    <cfset local.response = ArrayNew(1) />
    <cfset local.patient = getPatientGatewayObject().getPatient(PatientId)>

    <cfset local.patientObject = createObject("component", "Patient").init(argumentCollection=queryRowToStruct(local.patient)) />
    <cfset arrayAppend(local.response, local.patientObject) />

    <cfreturn local.response />

 </cffunction>

これは機能しますが、最終的には私が望むものではありません:

 <cffunction name="getPatient" access="remote" httpmethod="GET" returntype="Patient" produces="text/json" restpath="/{PatientId}">
    <cfargument name="PatientId" type="numeric" required="true" restargsource="Path" />

    <cfset local.response = ArrayNew(1) />
    <cfset local.patient = getPatientGatewayObject().getPatient(PatientId)>

    <cfset local.patientObject = createObject("component", "Patient").init(argumentCollection=queryRowToStruct(local.patient)) />
    <cfset arrayAppend(local.response, local.patientObject) />

    <cfreturn serializeJSON(local.response) />

 </cffunction>
4

0 に答える 0