/** * Converts the resource into an object. It is expected that the format of the resource would be * JSON * * @param classType * The type of object to convert the resource json into * @param <T> * The type T of the object being returned * @return The instantiated objecte */ public <T> T getJSONResourceObject(final Type classType) { return this.getJSONResourceObject(new Gson(), classType); }
/** * Creates a Challenge based on a JSON resource file * * @param checkName * The name of the check that will look for the json challenge info * @return The challenge based from the resource json file */ public static Challenge fromResource(final String checkName) { final ClassResource challenge = new ClassResource(checkName + FileSuffix.JSON.toString()); return challenge.getJSONResourceObject(Survey.class); }
/** * Helper function that converts the resource file into a {@link Challenge} * * @param resource * The path to the resource file * @return A {@link Challenge} object representing the provided resource. */ private Challenge getChallenge(final String resource) { final ClassResource challengeResource = new ClassResource(resource); final JsonObject challengeJSON = challengeResource.getJSONResourceObject(JsonObject.class); return getGson().fromJson(challengeJSON, Challenge.class); } }