eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'JSONTypeEncoder':

Home

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

Class: JSONTypeEncoder


Inheritance:

   Object
   |
   +--JSONTypeEncoder
      |
      +--JSONTypeEncoder::NullTypeEncoder
      |
      +--JSONTypeEncoder::STXTypeEncoder
      |
      +--JSONTypeEncoder::STXTypeEncoder2

Package:
stx:goodies/communication
Category:
Net-Communication-JSON
Version:
rev: 1.2 date: 2019/08/17 22:21:19
user: cg
file: JSONTypeEncoder.st directory: goodies/communication
module: stx stc-classLibrary: communication

Description:


<<END
    Instances of (subclasses of me) encode type encodings
    by wrapping stored values into some json composite object,
    or adding additional type-info slots.
    A NullTypeEncoder generates standard JSON (no type info)

                                                                        [exBegin]
    |o o0 o1 o2 s0 s1 s2 o1b o2b|

    o1 := Rectangle origin:(10@20) corner:(100@200).
    s0 := (JSONPrinter new typeInfoFormat:nil) encode:o1.   
        "/ -> '{"left":10,"top":20,"width":90,"height":180}' .
    s1 := (JSONPrinter new typeInfoFormat:#stx) encode:o1.    
        "/ -> '{"@__type__":"Rectangle","@__value__":{"left":10,"top":20,"width":90,"height":180}}' .
    s2 := (JSONPrinter new typeInfoFormat:#stx2) encode:o1.              
        "/ -> '{"@__type__":"Rectangle","left":10,"top":20,"width":90,"height":180}' .

    o0 := JSONReader fromJSON:s0.    "/ -> OrderedDictionary('left'->10 'top'->20 'width'->90 'height'->180)
    o1 := JSONReader fromJSON:s1.    "/ -> OrderedDictionary('@__type__'->'Rectangle' '@__value__'->OrderedDictionary('left'->10 'top'->20 'width'->90 'height'->180))
    o2 := JSONReader fromJSON:s2.    "/ -> OrderedDictionary('@__type__'->'Rectangle' 'left'->10 'top'->20 'width'->90 'height'->180)

    o1b := (JSONReader new typeInfoFormat:#stx) decode:s1.    
        "/ -> (10@20) extent: (90@180)
    o2b := (JSONReader new typeInfoFormat:#stx2) decode:s2.      
        "/ -> (10@20) extent: (90@180)
                                                                        [exEnd]
END>>


Class protocol:

instance creation
o  newEncoderFor: typeInfoFormat

queries
o  isAbstract
Return if this class is an abstract class.
True is returned here for myself only; false for subclasses.
Abstract subclasses must redefine this again.


Instance protocol:

accessing
o  printer: jsonPrinter

protocol
o  decodeArray: anArray

o  decodeDictionary: aDictionary

o  encode: anObject indent: indent on: aStream using: actionForStandardEncoding

o  encodeDate: aDate indent: indent on: aStream using: actionForStandardEncoding

o  encodeDictionary: aDictionary indent: indent on: aStream using: actionForStandardEncoding

o  encodeNumber: aNumber indent: indent on: aStream using: actionForStandardEncoding

o  encodeObject: anObject skipNil: skipNil indent: indent on: aStream

o  encodeSequenceableCollection: aCollection indent: indent on: aStream using: actionForStandardEncoding

o  encodeSlotsOfObject: someObject skipNil: skipNil indent: indent on: stream

o  encodeTime: aTime indent: indent on: aStream using: actionForStandardEncoding

o  encodeTimestamp: aTimestamp indent: indent on: aStream using: actionForStandardEncoding


Private classes:

    NullTypeEncoder
    STXTypeEncoder
    STXTypeEncoder2


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Thu, 28 Mar 2024 17:14:03 GMT