Serializer

- Cleaned up
- Added documentation

Deserializer

- Fixed documentation
This commit is contained in:
Tristan B. Velloza Kildaire 2023-06-23 08:38:15 +02:00
parent 40118feffb
commit 838ecb2a08
2 changed files with 17 additions and 11 deletions

View File

@ -2,19 +2,18 @@ module jstruct.deserializer;
import std.json; import std.json;
import jstruct.exceptions : SerializationError; import jstruct.exceptions : SerializationError;
import std.traits : FieldTypeTuple, FieldNameTuple; import std.traits : FieldTypeTuple, FieldNameTuple;
/** /**
* Deserializes the provided JSON into a struct of type RecordType * Deserializes the provided JSON into a struct of type RecordType
* *
* Params: * Params:
* jsonIn = the JSON to deserialize * jsonIn = the JSON to deserialize
* Throws: * Throws:
* RemoteFieldMissing = if the field names in the provided RecordType * RemoteFieldMissing = if the field names in the provided RecordType
* cannot be found within the prpvided JSONValue `jsonIn`. * cannot be found within the prpvided JSONValue `jsonIn`.
* Returns: an instance of RecordType * Returns: an instance of RecordType
*/ */
public RecordType fromJSON(RecordType)(JSONValue jsonIn) public RecordType fromJSON(RecordType)(JSONValue jsonIn)
{ {
RecordType record; RecordType record;

View File

@ -3,8 +3,15 @@ module jstruct.serializer;
import std.json; import std.json;
import std.conv : to; import std.conv : to;
import std.traits : FieldTypeTuple, FieldNameTuple; import std.traits : FieldTypeTuple, FieldNameTuple;
import std.traits : isArray; import std.traits : isArray;
/**
* Serializes the provided record into JSON
*
* Params:
* record = the record to serialize into
* Returns: A `JSONValue` containing the serialized record
*/
public JSONValue serializeRecord(RecordType)(RecordType record) public JSONValue serializeRecord(RecordType)(RecordType record)
{ {
// Final JSON to submit // Final JSON to submit