const mixinafJson::Json
afJson::Json
@
Js
(Service) - A one-stop shop for all your JSON mapping needs!
The methods in this service may be summarised as follows:
- converter
abstract EntityConverter converter()
Returns the underlying
EntityConverter
instance.- fromEntity
abstract Obj? fromEntity(Obj? entity, Type? entityType := null)
Converts the given entity instance to its
jsonObj
representation.If
entityType
isnull
it defaults toentity.typeof()
.- inspectors
abstract JsonTypeInspectors inspectors()
Returns the underlying
JsonTypeInspectors
instance.- jsonReader
abstract JsonReader jsonReader()
Returns the underlying
JsonReader
instance.- jsonWriter
abstract JsonWriter jsonWriter()
Returns the underlying
JsonWriter
instance.- make
static new make(JsonTypeInspectors? inspectors := null, JsonReader? reader := null, JsonWriter? writer := null)
Creates a new
Json
instance with the given inspectors.- readJson
abstract Obj? readJson(Str? json, Type? entityType := null)
Reads the the given JSON and (optionally) converts it to a Fantom entity instance.
The given JSON is read into a
jsonObj
. ShouldentityType
not be null then thejsonObj
is converted to a Fantom entity.- readJsonAsList
abstract Obj?[]? readJsonAsList(Str? json)
Translates the given JSON to its Fantom List representation.
Convenience for
(Obj?[]?) readJson(json, null)
- readJsonAsMap
abstract [Str:Obj?]? readJsonAsMap(Str? json)
Translates the given JSON to its Fantom Map representation.
Convenience for
([Str:Obj?]?) readJson(json, null)
- toEntity
abstract Obj? toEntity(Obj? jsonObj, Type entityType)
Converts the given
jsonObj
to a Fantom entity instance.- writeJson
abstract Str writeJson(Obj? obj, Type? entityType := null, Obj? prettyPrintOptions := null)
Converts the given obj to JSON.
If
entityType
is not null then the givenobj
is taken to be an entity and is first converted to anjsonObj
. ThejsonObj
is then written out to JSON.prettyPrintOptions
may be either aPrettyPrintOptions
instance, or justtrue
to enable pretty printing with defaults.