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
      |
      +--JSONTypeEncoder::STXTypeEncoder3

Package:
stx:goodies/communication
Category:
Net-Communication-JSON
Version:
rev: 1.26 date: 2022/07/12 05:59:22
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>>

copyright

COPYRIGHT (c) 2018 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

constants
o  typeInfoFormatNone
if set via typeInfoFormat:, slots are encoded in standard JSON (no type info)

o  typeInfoFormatSTX
if set via typeInfoFormat:,
slots are encoded as:
{ '@type': , <classNameString> , 'value': <encoding> }

o  typeInfoFormatSTX2
if set via typeInfoFormat:,
object are store with an additional slot, as:
{ '@type': , <classNameString> ,
...
... regular slots ...
...
}

o  typeInfoFormatSTX3
if set via typeInfoFormat:,
object are stored wrapped, as:
{ '@obj': , <id>
'@t': <classNameString> ,
'@v':
...
... regular slots (except dicts and sets)...
...
}
references are resolved as:
{ '@ref': , <id> }
dictionaries with non-string keys are stored as:
{ '@t': , <classNameString>
'@v': [
{ '@k': <key1> , '@v': <value> }
}

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  canRepresentAnyObject

o  canRepresentRecursiveObjects

o  classNamespace: something

o  printer: jsonPrinter

o  typeSlotName
to overwrite the slotName which provides the type information
(if not set, defaults to @__type__ in my subclasses).
If nil, no type info is present

o  typeSlotName: aString
to overwrite the slotName which provides the type information
(if not set, defaults to @__type__ in my subclasses)

private
o  resolveClassNamed: className

protocol
o  decodeArray: anArray

o  decodeDictionary: aDictionary

** This method must be redefined in concrete classes (subclassResponsibility) **

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  encodeSet: aSet indent: indent on: aStream using: actionForStandardEncoding

o  encodeSlotsOfObject: someObject skipNil: skipNil indent: indent on: stream
(printer prettyPrint and:[first not]) ifTrue:[stream cr; spaces:indent].

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

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


Private classes:

    NullTypeEncoder
    STXTypeEncoder
    STXTypeEncoder2
    STXTypeEncoder3


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 04:15:35 GMT