I recently had the need to store some static objects in methods and found what 
seems to be a fairly simple way. I have not tested it with anything large, but 
it might help spark some ideas.

John DeSoi, Ph.D.

===
  //Serialize the object to a 4D method.

  //$1 - Object.
  //$2 - Method name.

C_OBJECT($1)
C_TEXT($2)

C_TEXT($code)
C_OBJECT($oCheck)

  //C_OBJECT($0)
  //$0:=JSON Parse(string)
$code:=Command name(1216)+"($0)"+CR+\
"$0:="+Command name(1218)+"("+OB_Stringify_escaped ($1)+")"+CR

METHOD SET CODE($2;$code;*)

EXECUTE METHOD($2;$oCheck)  //Validate same object is returned.
ASSERT(OB_Equal ($1;$oCheck))

===

  //Stringify the object in a string (suitable for a method).

  //$0 - JSON string escaped.
  //$1 - Object.

C_TEXT($0)
C_OBJECT($1)


$0:=JSON Stringify(JSON Stringify($1))
==



> On Jan 6, 2017, at 6:13 PM, David Adams <[email protected]> wrote:
> 
> So, serialize the object,
> escape the text and then you get something like this:
> 
> C_TEXT($expected_good_object_with_name)
> $expected_good_object_with_name:="{\n\t\"header\": {\n\t\t\"type_name\":
> \"Foo_Object\",\n\t\t\"version_number\": 1.1,\n\t\t\"instance_name\":
> \"Test instance\"\n\t},\n\t\"body\": {}\n}"
> 
> Yeah, I'm going to write that sort of code by hand. Not.

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to