JString final
final class JString extends JsonA JSON string value.
Inheritance
Object → Json → JString
Constructors
JString() const
const JString(String value)Implementation
const JString(this.value);Properties
hashCode no setter inherited
int get hashCodeThe hash code for this object.
A hash code is a single integer which represents the state of the object that affects operator == comparisons.
All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).
If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.
Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.
Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.
If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.
Inherited from Json.
Implementation
@override
int get hashCode => fold(
() => 0,
(boolean) => boolean.hashCode,
(number) => number.hashCode,
(string) => string.hashCode,
(ilist) => ilist.hashCode,
(object) => object.keys.hashCode * object.values.hashCode,
);hcursor no setter inherited
HCursor get hcursorReturns an HCursor positioned at the root of this value.
Inherited from Json.
Implementation
HCursor get hcursor => HCursor.fromJson(this);isArray no setter override
bool get isArrayReturns true if this value is a JArray.
Implementation
@override
bool get isArray => false;isBoolean no setter override
bool get isBooleanReturns true if this value is a JBoolean.
Implementation
@override
bool get isBoolean => false;isNull no setter override
bool get isNullReturns true if this value is JNull.
Implementation
@override
bool get isNull => false;isNumber no setter override
bool get isNumberReturns true if this value is a JNumber.
Implementation
@override
bool get isNumber => false;isObject no setter override
bool get isObjectReturns true if this value is a JObject.
Implementation
@override
bool get isObject => false;isString no setter override
bool get isStringReturns true if this value is a JString.
Implementation
@override
bool get isString => true;runtimeType no setter inherited
Type get runtimeTypeA representation of the runtime type of the object.
Inherited from Object.
Implementation
external Type get runtimeType;value final
final String valueThe string value.
Implementation
final String value;Methods
asArray() override
Returns Some with the elements if this is JArray, otherwise None.
Implementation
@override
Option<IList<Json>> asArray() => none();asBoolean() override
Option<bool> asBoolean()Returns Some with the boolean if this is JBoolean, otherwise None.
Implementation
@override
Option<bool> asBoolean() => none();asNull() override
Returns Some with Unit if this is JNull, otherwise None.
Implementation
@override
Option<Unit> asNull() => none();asNumber() override
Option<num> asNumber()Returns Some with the number if this is JNumber, otherwise None.
Implementation
@override
Option<num> asNumber() => none();asObject() override
Option<JsonObject> asObject()Returns Some with the JsonObject if this is JObject, otherwise None.
Implementation
@override
Option<JsonObject> asObject() => none();asString() override
Option<String> asString()Returns Some with the string if this is JString, otherwise None.
Implementation
@override
Option<String> asString() => Some(value);deepDropNullValues() inherited
Json deepDropNullValues()Returns a copy with all JNull values removed recursively.
Inherited from Json.
Implementation
Json deepDropNullValues() => foldWith(_DropNullFolder());deepMerge() inherited
Recursively merges that into this value.
Object fields from this value take precedence; fields present in both are merged recursively. If either value is not a JObject, returns that.
Inherited from Json.
Implementation
Json deepMerge(Json that) => (asObject(), that.asObject())
.mapN(
(lhs, rhs) => fromJsonObject(
lhs.toIList().foldLeft(
rhs,
(acc, kv) => rhs
.get(kv.$1)
.fold(
() => acc.add(kv.$1, kv.$2),
(r) => acc.add(kv.$1, kv.$2.deepMerge(r)),
),
),
),
)
.getOrElse(() => that);dropNullValues() inherited
Json dropNullValues()Returns a copy with all top-level object fields whose value is JNull removed.
Inherited from Json.
Implementation
Json dropNullValues() => mapObject((a) => a.filter((keyValue) => !keyValue.$2.isNull));fold() inherited
A fold<A>(
A Function() jsonNull,
A Function(bool) jsonBoolean,
A Function(num) jsonNumber,
A Function(String) jsonString,
A Function(IList<Json>) jsonArray,
A Function(JsonObject) jsonObject,
)Pattern-matches this value, calling the corresponding function for each subtype.
Inherited from Json.
Implementation
A fold<A>(
Function0<A> jsonNull,
Function1<bool, A> jsonBoolean,
Function1<num, A> jsonNumber,
Function1<String, A> jsonString,
Function1<IList<Json>, A> jsonArray,
Function1<JsonObject, A> jsonObject,
) => switch (this) {
JNull _ => jsonNull(),
final JBoolean b => jsonBoolean(b.value),
final JNumber n => jsonNumber(n.value),
final JString s => jsonString(s.value),
final JArray a => jsonArray(a.value),
final JObject o => jsonObject(o.value),
};foldWith() override
A foldWith<A>(JsonFolder<A> folder)Dispatches to folder based on the runtime subtype of this value.
Implementation
@override
A foldWith<A>(JsonFolder<A> folder) => folder.onString(value);mapArray() override
If this is JArray, returns a JArray with the elements mapped through f; otherwise returns this unchanged.
Implementation
@override
Json mapArray(Function1<IList<Json>, IList<Json>> f) => this;mapBoolean() override
Json mapBoolean(bool Function(bool) f)If this is JBoolean, returns a JBoolean with the value mapped through f; otherwise returns this unchanged.
Implementation
@override
Json mapBoolean(Function1<bool, bool> f) => this;mapNumber() override
Json mapNumber(num Function(num) f)If this is JNumber, returns a JNumber with the value mapped through f; otherwise returns this unchanged.
Implementation
@override
Json mapNumber(Function1<num, num> f) => this;mapObject() override
Json mapObject(JsonObject Function(JsonObject) f)If this is JObject, returns a JObject with the JsonObject mapped through f; otherwise returns this unchanged.
Implementation
@override
Json mapObject(Function1<JsonObject, JsonObject> f) => this;mapString() override
Json mapString(String Function(String) f)If this is JString, returns a JString with the value mapped through f; otherwise returns this unchanged.
Implementation
@override
Json mapString(Function1<String, String> f) => JString(f(value));noSuchMethod() inherited
dynamic noSuchMethod(Invocation invocation)Invoked when a nonexistent method or property is accessed.
A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:
dynamic object = 1;
object.add(42); // Statically allowed, run-time errorThis invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).
Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.
A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:
class MockList<T> implements List<T> {
noSuchMethod(Invocation invocation) {
log(invocation);
super.noSuchMethod(invocation); // Will throw.
}
}
void main() {
MockList().add(42);
}This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.
If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.
The default behavior is to throw a NoSuchMethodError.
Inherited from Object.
Implementation
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);printWith() inherited
String printWith(Printer printer)Renders this value using printer.
Inherited from Json.
Implementation
String printWith(Printer printer) => printer.print(this);toString() override
String toString()A string representation of this object.
Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.
Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.
Implementation
@override
String toString() => 'JString("$value")';withArray() override
If this is JArray, returns f(elements); otherwise returns this unchanged.
Implementation
@override
Json withArray(Function1<IList<Json>, Json> f) => this;withBoolean() override
If this is JBoolean, returns f(value); otherwise returns this unchanged.
Implementation
@override
Json withBoolean(Function1<bool, Json> f) => this;withNull() override
If this is JNull, returns f(); otherwise returns this unchanged.
Implementation
@override
Json withNull(Function0<Json> f) => this;withNumber() override
If this is JNumber, returns f(value); otherwise returns this unchanged.
Implementation
@override
Json withNumber(Function1<num, Json> f) => this;withObject() override
Json withObject(Json Function(JsonObject) f)If this is JObject, returns f(object); otherwise returns this unchanged.
Implementation
@override
Json withObject(Function1<JsonObject, Json> f) => this;withString() override
If this is JString, returns f(value); otherwise returns this unchanged.
Implementation
@override
Json withString(Function1<String, Json> f) => f(value);Operators
operator ==() inherited
bool operator ==(Object other)The equality operator.
The default behavior for all Objects is to return true if and only if this object and other are the same object.
Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:
Total: It must return a boolean for all arguments. It should never throw.
Reflexive: For all objects
o,o == omust be true.Symmetric: For all objects
o1ando2,o1 == o2ando2 == o1must either both be true, or both be false.Transitive: For all objects
o1,o2, ando3, ifo1 == o2ando2 == o3are true, theno1 == o3must be true.
The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.
If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.
Inherited from Json.
Implementation
@override
bool operator ==(Object other) {
return fold(
() => other is JNull,
(boolean) => other is JBoolean && other.value == boolean,
(number) => other is JNumber && other.value == number,
(string) => other is JString && other.value == string,
(ilist) => other is JArray && other.value == ilist,
(object) => other is JObject && other.value == object,
);
}