Skip to content

Commit

Permalink
For #321: add encode.string() to resources
Browse files Browse the repository at this point in the history
  • Loading branch information
atuttle committed Jul 27, 2016
1 parent 296713a commit 5edf982
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/nativeJsonSerializer.cfc
Expand Up @@ -6,7 +6,7 @@
taffy:mime="application/json;text/json"
taffy:default="true"
hint="serializes data as JSON">
<cfreturn serializeJSON(variables.data) />
<cfreturn replace(serializeJSON(variables.data), chr(2), '', 'ALL') />
</cffunction>

</cfcomponent>
8 changes: 8 additions & 0 deletions core/resource.cfc
@@ -1,5 +1,13 @@
<cfcomponent hint="base class for taffy REST components">

<cffunction name="forceString">
<cfargument name="data" required="true" hint="the data that is being forced to serialize as a string" />
<cfreturn chr(2) & arguments.data />
</cffunction>

<cfset variables.encode = structNew() />
<cfset variables.encode.string = forceString />

<!--- helper functions --->
<cffunction name="representationOf" access="public" output="false" hint="returns an object capable of serializing the data in a variety of formats">
<cfargument name="data" required="true" hint="any simple or complex data that should be returned for the request" />
Expand Down
4 changes: 3 additions & 1 deletion examples/api/resources/artMember.cfc
Expand Up @@ -2,6 +2,8 @@

<cfset variables.dummyData = StructNew() />
<cfset variables.dummyData.whatever = true />
<cfset variables.dummyData.phone = encode.string(5558675309) />
<cfset variables.dummyData.phoneNumeric = 5558675309 />

<cffunction name="get" access="public" output="false">
<cfreturn representationOf(variables.dummyData).withStatus(200) />
Expand All @@ -19,4 +21,4 @@
<cfreturn representationOf(variables.dummyData).withStatus(200) />
</cffunction>

</cfcomponent>
</cfcomponent>

0 comments on commit 5edf982

Please sign in to comment.