|
Class: JSONPrinter
Object
|
+--Visitor
|
+--AspectVisitor
|
+--ObjectCoder
|
+--JSONPrinter
- Package:
- stx:goodies/communication
- Category:
- Net-Communication-JSON
- Version:
- rev:
1.15
date: 2018/05/09 17:37:36
- user: cg
- file: JSONPrinter.st directory: goodies/communication
- module: stx stc-classLibrary: communication
I encode a limited subset of smalltalk object types into a JSON representation.
Allowed are:
strings,
numbers
booleans,
nil,
Arrays and OrderedCollections,
Dictionaries,
Date & Time (careful - see >> useISODateFormat)
Everything else is not representable.
I do not handle recursive data structures.
Author:
Claus Gittinger
Loosely Based upon Public Domain Code from Robin Redeker published in lists.gnu.org
encoding / decoding
-
encode: anObject
-
-
toJSON: anObject
-
accessing
-
useISODateFormat
-
returns the date format generated.
If true (the default), a string containing the ISO format
is generated for Date, Time and Timestamp.
if false, a non-standard (but supported by some browsers) format
is generated (eg. 'new Date(y,m,d)').
usage example(s):
JSONPrinter new
encode:{ Date today . Time now . Timestamp now }.
JSONPrinter new
useISODateFormat:false;
encode:{ Date today . Time now . TimeStamp now }.
|
-
useISODateFormat: aBoolean
-
if true (the default), a string containing the ISO format
is generated for Date, Time and Timestamp.
if false, a non-standard (but supported by some browsers) format
is generated (eg. 'new Date(y,m,d)').
usage example(s):
JSONPrinter new
encode:{ Date today . Time now . Timestamp now }.
JSONPrinter new
useISODateFormat:false;
encode:{ Date today . Time now . TimeStamp now }.
|
encoding / decoding
-
encode: anObject
-
visiting
-
visitBoolean: aBoolean with: aParameter
-
(comment from inherited method)
visit a Boolean - fallback here is to call visitObject
-
visitDate: aDate with: aParameter
-
months start at 0
-
visitDictionary: aDictionary with: aParameter
-
(comment from inherited method)
visit a Dictionary
-
visitFloat: aFloat with: aParameter
-
(comment from inherited method)
visit a Float
-
visitInteger: anInteger with: aParameter
-
(comment from inherited method)
visit an Integer
-
visitNilWith: aParameter
-
(comment from inherited method)
visit nil - fallback here is to call visitObject
-
visitNumber: aNumber with: aParameter
-
(comment from inherited method)
visit any number - fallback here is to call visitObject
-
visitObject: someObject with: aParameter
-
encode the object like a dictionary, using the object's instVarNames as keys.
-
visitSequenceableCollection: aCollection with: aParameter
-
(comment from inherited method)
visit a SequenceableCollection
-
visitString: aString with: aParameter
-
(comment from inherited method)
visit a String - fallback here is to call visitObject
-
visitTime: aTime with: aParameter
-
JSONReader encode:{ Time now }
JSONPrinter new
useISODateFormat:false;
encode:{ Time now }
JSONReader decode:(JSONReader encode:{ Time now })
JSONReader decode:(JSONPrinter new
useISODateFormat:false;
encode:{ Time now })
-
visitTimestamp: aTimestamp with: aParameter
-
Month dd, yyyy hh:mm:ss
see examples in JSONReader
|