eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'JSONPrinter':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: JSONPrinter


Inheritance:

   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

Description:


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


Class protocol:

encoding / decoding
o  encode: anObject

o  toJSON: anObject


Instance protocol:

accessing
o  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 }.

o  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
o  encode: anObject

visiting
o  visitBoolean: aBoolean with: aParameter
(comment from inherited method)
visit a Boolean - fallback here is to call visitObject

o  visitDate: aDate with: aParameter
months start at 0

o  visitDictionary: aDictionary with: aParameter
(comment from inherited method)
visit a Dictionary

o  visitFloat: aFloat with: aParameter
(comment from inherited method)
visit a Float

o  visitInteger: anInteger with: aParameter
(comment from inherited method)
visit an Integer

o  visitNilWith: aParameter
(comment from inherited method)
visit nil - fallback here is to call visitObject

o  visitNumber: aNumber with: aParameter
(comment from inherited method)
visit any number - fallback here is to call visitObject

o  visitObject: someObject with: aParameter
encode the object like a dictionary, using the object's instVarNames as keys.

o  visitSequenceableCollection: aCollection with: aParameter
(comment from inherited method)
visit a SequenceableCollection

o  visitString: aString with: aParameter
(comment from inherited method)
visit a String - fallback here is to call visitObject

o  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 })

o  visitTimestamp: aTimestamp with: aParameter
Month dd, yyyy hh:mm:ss


Examples:


see examples in JSONReader

ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Wed, 19 Sep 2018 08:52:33 GMT