Php json decode to class7/10/2023 ![]() (current-json-key-for-slot (cdar *stack-of-object-ref*)) (current-class-symbol (caar *stack-of-object-ref*)) (let ((json::*prototype* top-level-prototype) root case dynamically re-bind *prototype* right around calling fn (let ((top-level-prototype (make-instance 'json::prototype :lisp-class root-class-symbol :lisp-package (find-symbol (package-name (symbol-package root-class-symbol)))))) "Utility code to unwrap JSON using cl-json::prototype and create instances of defined CLOS objects ()" ![]() (defun end-wrap-for-class (root-class-symbol &optional (fn json::*end-of-object-handler*)) (setf *stack-of-object-ref* (cons (cons class-symbol-of-reference-holder method-symbol-of-reference-holder) *stack-of-object-ref*))) stack push now that the three cases are resolved let's push the cons on the stack. (setf class-symbol-of-reference-holder root-class-symbol)))) else we are a first class object : use class-symbol. ![]() (get-slot-definition previous-class-symbol previous-json-key-for-slot))) if we are not in first class object : get the current class by using previous class and slot-definition-type. (previous-json-key-for-slot (cdar *stack-of-object-ref*))) (let ((previous-class-symbol (caar *stack-of-object-ref*)) (method-symbol-of-reference-holder *last-json-key-read*)) default case : we are on root object, don't do anything else. (let ((class-symbol-of-reference-holder nil) (defun start-wrap-for-class (root-class-symbol &optional (fn json::*beginning-of-object-handler*)) :test (lambda(a b) (string-equal a (symbol-name (closer-mop:slot-definition-name b)))))) "returns a slot-definition from the slot of class-symbol which is infered from using json-key / method symbol" (defun get-slot-definition (class-symbol json-key) (defvar *name-of-current-class-being-decoded*) (defvar *stack-of-object-ref*) holds elements as cons (class-name. and yes, I've just noticed while typing the code here that it's not compatible yet with json arrays :-/ dependencies I then have defgeneric make-instance-from-json ,so I can still overload that generic Json2CLOS engine depending on the root object to instantiate, without changing the call syntax.Īs I'm just beginning with lisp, what are your thoughts on that code (design/implementation) ?
0 Comments
Leave a Reply. |