class RestAuthLanguageCallbackHandler extends AbstractRestAuthCallbackHandler<LanguageCallback> {

    public LanguageCallback convertFromJson(LanguageCallback callback, JsonValue jsonCallback) throws RestAuthException {

        validateCallbackType(CALLBACK_NAME, jsonCallback);

        JsonValue input = jsonCallback.get("input");

        if (input.size() != 2) {
            throw new JsonException("JSON Callback does not include the required input fields");
        }

        String language = null;
        String country = null;

        for (int i = 0; i < input.size(); i++) {

            JsonValue inputField = input.get(i);

            String value = inputField.get("value").asString();

            if (i == 0) {
                language = value;
            } else {
                country = value;
            }
        }

        callback.setLocale(createLocale(language, country));

        return callback;
    }

}