@Test public void shouldConvertToJson() { ChoiceCallback choiceCallback = new ChoiceCallback("Select choice:", new String[]{"1", "34", "66", "93"}, 0, false); JsonValue jsonObject = restAuthChoiceCallbackHandler.convertToJson(choiceCallback, 1); assertEquals("ChoiceCallback", jsonObject.get("type").asString()); assertNotNull(jsonObject.get("output")); assertEquals(3, jsonObject.get("output").size()); assertEquals("Select choice:", jsonObject.get("output").get(0).get("value").asString()); assertEquals("1", jsonObject.get("output").get(1).get("value").get(0).asString()); assertEquals("34", jsonObject.get("output").get(1).get("value").get(1).asString()); assertEquals("66", jsonObject.get("output").get(1).get("value").get(2).asString()); assertEquals("93", jsonObject.get("output").get(1).get("value").get(3).asString()); assertEquals(0, (int) jsonObject.get("output").get(2).get("value").asInteger()); assertNotNull(jsonObject.get("input")); assertEquals(1, jsonObject.get("input").size()); assertEquals(0, (int) jsonObject.get("input").get(0).get("value").asInteger()); }
public JsonValue convertToJson(ChoiceCallback callback, int index) { String prompt = callback.getPrompt(); String[] choices = callback.getChoices(); int defaultChoice = callback.getDefaultChoice(); int[] selectedIndexes = callback.getSelectedIndexes(); int selectedIndex = 0; if (selectedIndexes != null) { selectedIndex = selectedIndexes[0]; } JsonValue jsonValue = JsonValueBuilder.jsonValue() .put("type", CALLBACK_NAME) .array("output") .add(createOutputField("prompt", prompt)) .add(createOutputField("choices", choices)) .addLast(createOutputField("defaultChoice", defaultChoice)) .array("input") .addLast(createInputField(index, selectedIndex)) .build(); return jsonValue; }
RestAuthChoiceCallbackHandler extends AbstractRestAuthCallbackHandler<ChoiceCallback> { public JsonValue convertToJson(ChoiceCallback callback, int index) { String prompt = callback.getPrompt(); String[] choices = callback.getChoices(); int defaultChoice = callback.getDefaultChoice(); int[] selectedIndexes = callback.getSelectedIndexes(); int selectedIndex = 0; if (selectedIndexes != null) { selectedIndex = selectedIndexes[0]; } JsonValue jsonValue = JsonValueBuilder.jsonValue() .put("type", CALLBACK_NAME) .array("output") .add(createOutputField("prompt", prompt)) .add(createOutputField("choices", choices)) .addLast(createOutputField("defaultChoice", defaultChoice)) .array("input") .addLast(createInputField(index, selectedIndex)) .build(); return jsonValue; } }
RestAuthChoiceCallbackHandler extends AbstractRestAuthCallbackHandler<ChoiceCallback> { public JsonValue convertToJson(ChoiceCallback callback, int index) { String prompt = callback.getPrompt(); String[] choices = callback.getChoices(); int defaultChoice = callback.getDefaultChoice(); int[] selectedIndexes = callback.getSelectedIndexes(); int selectedIndex = 0; if (selectedIndexes != null) { selectedIndex = selectedIndexes[0]; } JsonValue jsonValue = JsonValueBuilder.jsonValue() .put("type", CALLBACK_NAME) .array("output") .add(createOutputField("prompt", prompt)) .add(createOutputField("choices", choices)) .addLast(createOutputField("defaultChoice", defaultChoice)) .array("input") .addLast(createInputField(index, selectedIndex)) .build(); return jsonValue; }  }
RestAuthChoiceCallbackHandler extends AbstractRestAuthCallbackHandler<ChoiceCallback> { public JsonValue convertToJson(ChoiceCallback callback, int index) { String prompt = callback.getPrompt(); String[] choices = callback.getChoices(); int defaultChoice = callback.getDefaultChoice(); int[] selectedIndexes = callback.getSelectedIndexes(); int selectedIndex = 0; if (selectedIndexes != null) { selectedIndex = selectedIndexes[0]; } JsonValue jsonValue = JsonValueBuilder.jsonValue() .put("type", CALLBACK_NAME) .array("output") .add(createOutputField("prompt", prompt)) .add(createOutputField("choices", choices)) .addLast(createOutputField("defaultChoice", defaultChoice)) .array("input") .addLast(createInputField(index, selectedIndex)) .build(); return jsonValue; }  ChoiceCallback handle(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, ChoiceCallback originalCallback); String getCallbackClassName(); JsonValue convertToJson(ChoiceCallback callback, int index); ChoiceCallback convertFromJson(ChoiceCallback callback, JsonValue jsonCallback); }
RestAuthChoiceCallbackHandler extends AbstractRestAuthCallbackHandler<ChoiceCallback> { public JsonValue convertToJson(ChoiceCallback callback, int index) { String prompt = callback.getPrompt(); String[] choices = callback.getChoices(); int defaultChoice = callback.getDefaultChoice(); int[] selectedIndexes = callback.getSelectedIndexes(); int selectedIndex = 0; if (selectedIndexes != null) { selectedIndex = selectedIndexes[0]; } JsonValue jsonValue = JsonValueBuilder.jsonValue() .put("type", CALLBACK_NAME) .array("output") .add(createOutputField("prompt", prompt)) .add(createOutputField("choices", choices)) .addLast(createOutputField("defaultChoice", defaultChoice)) .array("input") .addLast(createInputField(index, selectedIndex)) .build(); return jsonValue; }  ChoiceCallback handle(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, ChoiceCallback originalCallback); String getCallbackClassName(); JsonValue convertToJson(ChoiceCallback callback, int index); ChoiceCallback convertFromJson(ChoiceCallback callback, JsonValue jsonCallback);  }