@Test public void shouldConvertFromJson() { LanguageCallback languageCallback = new LanguageCallback(); JsonValue jsonLanguageCallback = JsonValueBuilder.jsonValue() .array("input") .add(JsonValueBuilder.jsonValue().put("value", "language").build()) .addLast(JsonValueBuilder.jsonValue().put("value", "COUNTRY").build()) .put("type", "LanguageCallback") .build(); LanguageCallback convertedLanguageCallback = restAuthLanguageCallbackHandler.convertFromJson( languageCallback, jsonLanguageCallback); assertEquals(languageCallback, convertedLanguageCallback); Assert.assertNotNull(convertedLanguageCallback.getLocale()); assertEquals("language", convertedLanguageCallback.getLocale().getLanguage()); assertEquals("COUNTRY", convertedLanguageCallback.getLocale().getCountry()); }
public LanguageCallback convertFromJson(LanguageCallback callback, JsonValue jsonCallback) { 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; }
RestAuthLanguageCallbackHandler extends AbstractRestAuthCallbackHandler<LanguageCallback> { public LanguageCallback convertFromJson(LanguageCallback callback, JsonValue jsonCallback) { 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; } }
RestAuthLanguageCallbackHandler extends AbstractRestAuthCallbackHandler<LanguageCallback> { public LanguageCallback convertFromJson(LanguageCallback callback, JsonValue jsonCallback) { 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; }  }
RestAuthLanguageCallbackHandler extends AbstractRestAuthCallbackHandler<LanguageCallback> { public LanguageCallback convertFromJson(LanguageCallback callback, JsonValue jsonCallback) { 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; }  LanguageCallback handle(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, LanguageCallback originalCallback); String getCallbackClassName(); JsonValue convertToJson(LanguageCallback callback, int index); LanguageCallback convertFromJson(LanguageCallback callback, JsonValue jsonCallback); }
RestAuthLanguageCallbackHandler extends AbstractRestAuthCallbackHandler<LanguageCallback> { public LanguageCallback convertFromJson(LanguageCallback callback, JsonValue jsonCallback) { 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; }  LanguageCallback handle(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, LanguageCallback originalCallback); String getCallbackClassName(); JsonValue convertToJson(LanguageCallback callback, int index); LanguageCallback convertFromJson(LanguageCallback callback, JsonValue jsonCallback);  }