pod util

Utilities

Mixins

Service

Services are used to publish functionality in a VM for use by other software components.

Classes

AbstractMain

AbstractMain provides conveniences for writing the main routine of an app.

BoolArray
CsvInStream

CsvInStream is used to read delimiter-separated values as specified by RFC 4180.

CsvOutStream

CsvOutStream is used to write delimiter-separated values as specified by RFC 4180.

FileLogger

FileLogger appends Str log entries to a file.

FloatArray
IntArray
JVal

JSON Object

Macro

Macro provides a way to replace macro expressions within a pattern using a pluggable implementation for the macro resolution.

Random

Random provides different implementation of random number generators with more flexibility than the methods available in sys.

Unit

Unit models a unit of measurement.

Facets

Arg

Facet for annotating an AbstractMain argument field.

Opt

Facet for annotating an AbstractMain option field.

JSON

The json APIs provide basic serialization between Fantom and Javascript Object Notation (JSON). Refer to json.org for more information about JSON.

Type Mapping

JSON types are mapped to Fantom types as follows:

JSON     Fantom
------   --------
object   Str:Obj?
array    Obj?[]
string   Str
number   Int or Float
true     Bool
false    Bool
null     null

In addition when writing Fantom objects the following is supported:

Writing simples or serializables do not "roundtrip". For example if you write a Date it is written and will be read back as a normal string.

Writing Json

Writing is accomplised via JsonOutStream. To write to standard out:

map := ["key":"value", "intKey":123]
JsonOutStream(Env.cur.out).writeJson(map)

You can also use the writeToStr as a convenience to write to an in-memory string.

Reading Json

Reading JSON is accomplised via JsonInStream which takes raw JSON from a stream and produces of the core JSON types. For example:

str := """{"k1":"v1", "k2":3.4159, "k3":[1,2,3], "k4": {"m1":true, "m2":null}}"""
Str:Obj? data := JsonInStream(str.in).readJson
data["k1"]  =>  v1