STON.st
changeset 0 8f9f6be6af89
equal deleted inserted replaced
-1:000000000000 0:8f9f6be6af89
       
     1 "{ Package: 'stx:goodies/ston' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 Object subclass:#STON
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'STON-Core-Facade'
       
    10 !
       
    11 
       
    12 !STON class methodsFor:'accessing'!
       
    13 
       
    14 associationClass
       
    15 	^ Association
       
    16 !
       
    17 
       
    18 classNameKey
       
    19 	^ #className
       
    20 !
       
    21 
       
    22 jsonWriter
       
    23 	^ STONWriter new
       
    24 			jsonMode: true;
       
    25 			referencePolicy: #error;
       
    26 			yourself
       
    27 !
       
    28 
       
    29 listClass
       
    30 	^ Array
       
    31 !
       
    32 
       
    33 mapClass
       
    34 	^ Dictionary
       
    35 !
       
    36 
       
    37 reader
       
    38 	^ STONReader new
       
    39 !
       
    40 
       
    41 writer
       
    42 	^ STONWriter new
       
    43 ! !
       
    44 
       
    45 !STON class methodsFor:'convencience'!
       
    46 
       
    47 fromStream: readStream
       
    48 	^ (self reader on: readStream) next
       
    49 !
       
    50 
       
    51 fromStreamWithComments: readStream
       
    52 	^ (self reader on: (STONCStyleCommentsSkipStream on: readStream)) next
       
    53 !
       
    54 
       
    55 fromString: string
       
    56 	^ self fromStream: string readStream
       
    57 !
       
    58 
       
    59 fromStringWithComments: string
       
    60 	^ self fromStreamWithComments: string readStream
       
    61 !
       
    62 
       
    63 put: object asJsonOnStream: stream
       
    64 	(self jsonWriter on: stream) nextPut: object
       
    65 !
       
    66 
       
    67 put: object asJsonOnStreamPretty: stream
       
    68 	(self jsonWriter on: stream)
       
    69 		prettyPrint: true; 
       
    70 		nextPut: object
       
    71 !
       
    72 
       
    73 put: object onStream: stream
       
    74 	(self writer on: stream) nextPut: object
       
    75 !
       
    76 
       
    77 put: object onStreamPretty: stream
       
    78 	(self writer on: stream)
       
    79 		prettyPrint: true; 
       
    80 		nextPut: object
       
    81 !
       
    82 
       
    83 toJsonString: object
       
    84 	^ String streamContents: [ :stream |
       
    85 		self put: object asJsonOnStream: stream ]
       
    86 !
       
    87 
       
    88 toJsonStringPretty: object
       
    89 	^ String streamContents: [ :stream |
       
    90 		self put: object asJsonOnStreamPretty: stream ]
       
    91 !
       
    92 
       
    93 toString: object
       
    94 	^ String streamContents: [ :stream |
       
    95 		self put: object onStream: stream ]
       
    96 !
       
    97 
       
    98 toStringPretty: object
       
    99 	^ String streamContents: [ :stream |
       
   100 		self put: object onStreamPretty: stream ]
       
   101 ! !
       
   102