|
Class: JSONTypeEncoder
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
<<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>>
copyrightCOPYRIGHT (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.
constants
-
typeInfoFormatNone
-
if set via typeInfoFormat:, slots are encoded in standard JSON (no type info)
-
typeInfoFormatSTX
-
if set via typeInfoFormat:,
slots are encoded as:
{ '@type': , <classNameString> , 'value': <encoding> }
-
typeInfoFormatSTX2
-
if set via typeInfoFormat:,
object are store with an additional slot, as:
{ '@type': , <classNameString> ,
...
... regular slots ...
...
}
-
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
-
newEncoderFor: typeInfoFormat
-
queries
-
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.
accessing
-
canRepresentAnyObject
-
-
canRepresentRecursiveObjects
-
-
classNamespace: something
-
-
printer: jsonPrinter
-
-
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
-
typeSlotName: aString
-
to overwrite the slotName which provides the type information
(if not set, defaults to @__type__ in my subclasses)
private
-
resolveClassNamed: className
-
protocol
-
decodeArray: anArray
-
-
decodeDictionary: aDictionary
-
** This method must be redefined in concrete classes (subclassResponsibility) **
-
encode: anObject indent: indent on: aStream using: actionForStandardEncoding
-
-
encodeDate: aDate indent: indent on: aStream using: actionForStandardEncoding
-
-
encodeDictionary: aDictionary indent: indent on: aStream using: actionForStandardEncoding
-
-
encodeNumber: aNumber indent: indent on: aStream using: actionForStandardEncoding
-
-
encodeObject: anObject skipNil: skipNil indent: indent on: aStream
-
-
encodeSequenceableCollection: aCollection indent: indent on: aStream using: actionForStandardEncoding
-
-
encodeSet: aSet indent: indent on: aStream using: actionForStandardEncoding
-
-
encodeSlotsOfObject: someObject skipNil: skipNil indent: indent on: stream
-
(printer prettyPrint and:[first not]) ifTrue:[stream cr; spaces:indent].
-
encodeTime: aTime indent: indent on: aStream using: actionForStandardEncoding
-
-
encodeTimestamp: aTimestamp indent: indent on: aStream using: actionForStandardEncoding
-
NullTypeEncoder
STXTypeEncoder
STXTypeEncoder2
STXTypeEncoder3
|