Encode#
Converts a typed result, such as a ScheduleResult or an ApplyReport, into JSON text. The text is the same value that Wire and JsonProject put in the result field of a success envelope. All the members you call are static.
Declaration#
;
The class also has public static writers that take a WireWriter (write, schedule, apply, mutation, ...). WireWriter is package-private, so code outside org.dhtmlx.plen can't call them. Use text.
Static methods#
text#
public static String
Returns the JSON text of result. Object keys are sorted. Optional fields that are null on the record are left out. Numbers and dates are written as Json.stringify writes them, and dates come out as "YYYY-MM-DD HH:mm".
Parameters
| Name | Type | Description |
|---|---|---|
result |
Object |
The value to encode. See Accepted values. null gives "null". |
Returns the JSON text, without an envelope. To wrap it as {"ok":true,"result":...}, call Wire.resultText(result).
Errors
| Error | When |
|---|---|
IllegalStateException |
A number or numeric id in result is NaN or infinite |
UnsupportedOperationException |
result, or an element of an Iterable, is a type with no encoder, such as ProjectData or a Map |
Accepted values#
| Value | JSON |
|---|---|
Operation results: ScheduleResult, ApplyReport, LevelingResult, EvaluateResult, SuggestResult, LoadProfile, StateDoc |
An object, as in the operation's success envelope |
The records nested inside those results, such as Mutation, Conflict, Note, Slot, RejectedOperation, LevelingOptions |
An object, as it appears inside the parent result |
InputException |
{"kind","message","path"}. path is left out when it's null |
ProjectException |
The kebab-case code string, such as "needs-resync" |
Enums (TimeUnit, CalendarMode, Basis, MutationKind, ProjectError, ...) |
The lowercase wire spelling, such as "day" |
Id |
A string or a number, matching the id's form |
Moment |
"YYYY-MM-DD HH:mm" |
String, Character, Boolean, Double, Byte, Integer, Long |
A JSON string, boolean or number |
Iterable (Vec, List, ...) |
An array, with each element encoded by the same rules |
Example#
;
;
Related#
Decode- the reverse direction, JSON to typed recordsWire- wraps encoded results in envelopesJson- the writer for plain trees- Results as JSON - writing a schedule result as JSON