public TimeUnit deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String unit = json.getAsString(); TimeUnit tu; try { tu = TimeUnit.from(unit); } catch (IllegalArgumentException e) { throw new ContextualJsonSyntaxException( unit, "is not a valid time unit, must be one of " + TimeUnit.toValueNames()); } return tu; }