diff options
Diffstat (limited to 'src/data/ValidatingJsonDeserializer.java')
-rw-r--r-- | src/data/ValidatingJsonDeserializer.java | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/data/ValidatingJsonDeserializer.java b/src/data/ValidatingJsonDeserializer.java index 1474de3..5dca3bd 100644 --- a/src/data/ValidatingJsonDeserializer.java +++ b/src/data/ValidatingJsonDeserializer.java @@ -55,24 +55,26 @@ public class ValidatingJsonDeserializer<T> implements JsonDeserializer<T> { private void tryValidateProperty(String path, JsonElement je, Field f) { // assume that this annotation is only applied to objects Validator v = f.getAnnotation(Validator.class); + path += f.getName(); if (v != null) { Class<?> type = f.getType(); if (type.isArray()) { // the class expects an array, so the value must have one too. if (!je.isJsonArray()) { - throw new JsonParseException("Not an array: " + path + f.getName()); + throw new JsonParseException("Expected array: " + path); } JsonArray ja = je.getAsJsonArray(); type = type.getComponentType(); // for each array element, check if the object is valid. - path += f.getName() + "."; // e.g. foo[] for (JsonElement arr_je : ja) { - checkObject(path, arr_je, type); + checkObject(path + ".", arr_je, type); } } else { // not an array, assume a verifiable object - path += f.getName() + "."; // e.g. foo - checkObject(path, je, type); + if (!je.isJsonObject()) { + throw new JsonParseException("Expected object: " + path); + } + checkObject(path + ".", je, type); } } } |