[bknr-cvs] hans changed trunk/libraries/yason/
BKNR Commits
bknr at bknr.net
Mon Dec 1 12:23:47 UTC 2008
Revision: 4103
Author: hans
URL: http://bknr.net/trac/changeset/4103
Add methods to serialize objects and slots, moved here from application
code.
U trunk/libraries/yason/encode.lisp
U trunk/libraries/yason/package.lisp
Modified: trunk/libraries/yason/encode.lisp
===================================================================
--- trunk/libraries/yason/encode.lisp 2008-11-30 10:29:40 UTC (rev 4102)
+++ trunk/libraries/yason/encode.lisp 2008-12-01 12:23:46 UTC (rev 4103)
@@ -47,6 +47,14 @@
(encode (float object) stream)
object)
+(defmethod encode ((object double-float) &optional (stream *standard-output*))
+ (encode (coerce object 'single-float) stream)
+ object)
+
+(defmethod encode ((object float) &optional (stream *standard-output*))
+ (princ object stream)
+ object)
+
(defmethod encode ((object integer) &optional (stream *standard-output*))
(princ object stream))
@@ -212,3 +220,19 @@
(progn , at body)
(setf (car (stack *json-output*)) #\,))))
+(defgeneric encode-slots (object)
+ (:method-combination progn)
+ (:documentation
+ "Generic function to encode objects. Every class in a hierarchy
+ implements a method for ENCODE-OBJECT that serializes its slots.
+ It is a PROGN generic function so that for a given instance, all
+ slots are serialized by invoking the ENCODE-OBJECT method for all
+ classes that it inherits from."))
+
+(defgeneric encode-object (object)
+ (:documentation
+ "Encode OBJECT, presumably a CLOS object as a JSON object, invoking
+ the ENCODE-SLOTS method as appropriate.")
+ (:method (object)
+ (with-object ()
+ (json:encode-slots object))))
\ No newline at end of file
Modified: trunk/libraries/yason/package.lisp
===================================================================
--- trunk/libraries/yason/package.lisp 2008-11-30 10:29:40 UTC (rev 4102)
+++ trunk/libraries/yason/package.lisp 2008-12-01 12:23:46 UTC (rev 4103)
@@ -23,6 +23,8 @@
;; Basic encoder interface
#:encode
+ #:encode-slots
+ #:encode-object
;; Streaming encoder interface
#:with-output
More information about the Bknr-cvs
mailing list