mirror of https://github.com/Hax-io/jstruct
Compare commits
3 Commits
2f4570d0fa
...
47b2a318da
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | 47b2a318da | |
Tristan B. Velloza Kildaire | a15e0b5bcb | |
Tristan B. Velloza Kildaire | dad7e04ccf |
|
@ -4,7 +4,7 @@
|
|||
module jstruct.deserializer;
|
||||
|
||||
import std.json;
|
||||
import jstruct.exceptions : SerializationError;
|
||||
import jstruct.exceptions : DeserializationError;
|
||||
import std.traits : FieldTypeTuple, FieldNameTuple, isArray;
|
||||
|
||||
/**
|
||||
|
@ -191,8 +191,7 @@ public RecordType fromJSON(RecordType)(JSONValue jsonIn)
|
|||
}
|
||||
catch(JSONException e)
|
||||
{
|
||||
// TOOD: Should be DEserialization error
|
||||
throw new SerializationError();
|
||||
throw new DeserializationError();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,7 +286,7 @@ unittest
|
|||
Person person = fromJSON!(Person)(json);
|
||||
assert(false);
|
||||
}
|
||||
catch(SerializationError)
|
||||
catch(DeserializationError)
|
||||
{
|
||||
assert(true);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
/**
|
||||
* Exception types
|
||||
*/
|
||||
module jstruct.exceptions;
|
||||
|
||||
/**
|
||||
* General exception type
|
||||
*/
|
||||
public abstract class JStructException : Exception
|
||||
{
|
||||
this(string msg)
|
||||
|
@ -8,6 +14,9 @@ public abstract class JStructException : Exception
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error on serialization
|
||||
*/
|
||||
public final class SerializationError : JStructException
|
||||
{
|
||||
this()
|
||||
|
@ -15,3 +24,14 @@ public final class SerializationError : JStructException
|
|||
super("Error serializing");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error on deserialization
|
||||
*/
|
||||
public final class DeserializationError : JStructException
|
||||
{
|
||||
this()
|
||||
{
|
||||
super("Error deserializing");
|
||||
}
|
||||
}
|
|
@ -13,4 +13,7 @@ public import jstruct.serializer;
|
|||
*/
|
||||
public import jstruct.deserializer;
|
||||
|
||||
/**
|
||||
* Exception types
|
||||
*/
|
||||
public import jstruct.exceptions;
|
|
@ -34,9 +34,6 @@ public JSONValue serializeRecord(RecordType)(RecordType record)
|
|||
// pragma(msg, structValues[cnt]);
|
||||
}
|
||||
|
||||
import std.traits : isArray;
|
||||
|
||||
|
||||
static if(__traits(isSame, structTypes[cnt], int))
|
||||
{
|
||||
builtJSON[structNames[cnt]] = structValues[cnt];
|
||||
|
@ -68,7 +65,6 @@ public JSONValue serializeRecord(RecordType)(RecordType record)
|
|||
else static if(isArray!(structTypes[cnt]))
|
||||
{
|
||||
builtJSON[structNames[cnt]] = structValues[cnt];
|
||||
// pragma(msg, "WAIT", "d"~mixin(structTypes[cnt]));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue