@Test public void shouldConvertFromJsonWithStringChoice() { ConfirmationCallback confirmationCallback = new ConfirmationCallback("Select confirmation:", ConfirmationCallback.INFORMATION, new String[]{"OK", "NO", "CANCEL"}, 0); JsonValue jsonConfirmationCallback = JsonValueBuilder.jsonValue() .array("input") .addLast(JsonValueBuilder.jsonValue().put("value", 2).build()) .array("output") .add(JsonValueBuilder.jsonValue().put("value", "Select confirmation:").build()) .add(JsonValueBuilder.jsonValue().put("value", 0).build()) .add(JsonValueBuilder.jsonValue().put("value", new String[]{"OK", "NO", "CANCEL"}).build()) .add(JsonValueBuilder.jsonValue().put("value", -1).build()) .addLast(JsonValueBuilder.jsonValue().put("value", "0").build()) .put("type", "ConfirmationCallback") .build(); ConfirmationCallback convertedConfirmationCallback = restAuthConfirmationCallbackHandler.convertFromJson( confirmationCallback, jsonConfirmationCallback); assertEquals(confirmationCallback, convertedConfirmationCallback); assertEquals("Select confirmation:", convertedConfirmationCallback.getPrompt()); assertEquals(ConfirmationCallback.INFORMATION, convertedConfirmationCallback.getMessageType()); assertEquals("OK", convertedConfirmationCallback.getOptions()[0]); assertEquals("NO", convertedConfirmationCallback.getOptions()[1]); assertEquals("CANCEL", convertedConfirmationCallback.getOptions()[2]); assertEquals(-1, convertedConfirmationCallback.getOptionType()); assertEquals(0, convertedConfirmationCallback.getDefaultOption()); assertEquals(2, convertedConfirmationCallback.getSelectedIndex()); }
public ConfirmationCallback convertFromJson(ConfirmationCallback callback, JsonValue jsonCallback) { validateCallbackType(CALLBACK_NAME, jsonCallback); JsonValue input = jsonCallback.get("input"); if (input.size() != 1) { throw new JsonException("JSON Callback does not include a input field"); } JsonValue inputFieldValue = input.get(0).get("value").required(); int value; if (inputFieldValue.isString()) { value = Integer.parseInt(inputFieldValue.asString()); } else { value = inputFieldValue.asInteger(); } callback.setSelectedIndex(value); return callback; }
RestAuthConfirmationCallbackHandler extends AbstractRestAuthCallbackHandler<ConfirmationCallback> { public ConfirmationCallback convertFromJson(ConfirmationCallback callback, JsonValue jsonCallback) { validateCallbackType(CALLBACK_NAME, jsonCallback); JsonValue input = jsonCallback.get("input"); if (input.size() != 1) { throw new JsonException("JSON Callback does not include a input field"); } JsonValue inputFieldValue = input.get(0).get("value").required(); int value; if (inputFieldValue.isString()) { value = Integer.parseInt(inputFieldValue.asString()); } else { value = inputFieldValue.asInteger(); } callback.setSelectedIndex(value); return callback; } }
RestAuthConfirmationCallbackHandler extends AbstractRestAuthCallbackHandler<ConfirmationCallback> { public ConfirmationCallback convertFromJson(ConfirmationCallback callback, JsonValue jsonCallback) { validateCallbackType(CALLBACK_NAME, jsonCallback); JsonValue input = jsonCallback.get("input"); if (input.size() != 1) { throw new JsonException("JSON Callback does not include a input field"); } JsonValue inputFieldValue = input.get(0).get("value").required(); int value; if (inputFieldValue.isString()) { value = Integer.parseInt(inputFieldValue.asString()); } else { value = inputFieldValue.asInteger(); } callback.setSelectedIndex(value); return callback; }  }
RestAuthConfirmationCallbackHandler extends AbstractRestAuthCallbackHandler<ConfirmationCallback> { public ConfirmationCallback convertFromJson(ConfirmationCallback callback, JsonValue jsonCallback) { validateCallbackType(CALLBACK_NAME, jsonCallback); JsonValue input = jsonCallback.get("input"); if (input.size() != 1) { throw new JsonException("JSON Callback does not include a input field"); } JsonValue inputFieldValue = input.get(0).get("value").required(); int value; if (inputFieldValue.isString()) { value = Integer.parseInt(inputFieldValue.asString()); } else { value = inputFieldValue.asInteger(); } callback.setSelectedIndex(value); return callback; }  ConfirmationCallback handle(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, ConfirmationCallback originalCallback); String getCallbackClassName(); JsonValue convertToJson(ConfirmationCallback callback, int index); ConfirmationCallback convertFromJson(ConfirmationCallback callback, JsonValue jsonCallback); }
RestAuthConfirmationCallbackHandler extends AbstractRestAuthCallbackHandler<ConfirmationCallback> { public ConfirmationCallback convertFromJson(ConfirmationCallback callback, JsonValue jsonCallback) { validateCallbackType(CALLBACK_NAME, jsonCallback); JsonValue input = jsonCallback.get("input"); if (input.size() != 1) { throw new JsonException("JSON Callback does not include a input field"); } JsonValue inputFieldValue = input.get(0).get("value").required(); int value; if (inputFieldValue.isString()) { value = Integer.parseInt(inputFieldValue.asString()); } else { value = inputFieldValue.asInteger(); } callback.setSelectedIndex(value); return callback; }  ConfirmationCallback handle(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, ConfirmationCallback originalCallback); String getCallbackClassName(); JsonValue convertToJson(ConfirmationCallback callback, int index); ConfirmationCallback convertFromJson(ConfirmationCallback callback, JsonValue jsonCallback);  }