mirror of https://github.com/Hax-io/jstruct
Exceptions
- Added `DeserializationError` Deserializer - On error now throws `DeserializationError` exception
This commit is contained in:
parent
2f4570d0fa
commit
dad7e04ccf
|
@ -4,7 +4,7 @@
|
||||||
module jstruct.deserializer;
|
module jstruct.deserializer;
|
||||||
|
|
||||||
import std.json;
|
import std.json;
|
||||||
import jstruct.exceptions : SerializationError;
|
import jstruct.exceptions : DeserializationError;
|
||||||
import std.traits : FieldTypeTuple, FieldNameTuple, isArray;
|
import std.traits : FieldTypeTuple, FieldNameTuple, isArray;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -191,8 +191,7 @@ public RecordType fromJSON(RecordType)(JSONValue jsonIn)
|
||||||
}
|
}
|
||||||
catch(JSONException e)
|
catch(JSONException e)
|
||||||
{
|
{
|
||||||
// TOOD: Should be DEserialization error
|
throw new DeserializationError();
|
||||||
throw new SerializationError();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +286,7 @@ unittest
|
||||||
Person person = fromJSON!(Person)(json);
|
Person person = fromJSON!(Person)(json);
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
catch(SerializationError)
|
catch(DeserializationError)
|
||||||
{
|
{
|
||||||
assert(true);
|
assert(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,3 +15,11 @@ public final class SerializationError : JStructException
|
||||||
super("Error serializing");
|
super("Error serializing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final class DeserializationError : JStructException
|
||||||
|
{
|
||||||
|
this()
|
||||||
|
{
|
||||||
|
super("Error deserializing");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue