@Override public void serialize(JsonObject jsonObject, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { if (jsonObject == null) { return; } Map<String, Object> asMap = jsonObject.convertToPlainMap(); gen.writeObject(asMap); } };
public SpincastCsrfToken getCurrentCsrfToken(boolean createItIfNoneExists) { SpincastCsrfToken spincastCsrfToken = null; SpincastSession currentSession = getSpincastSessionManager().getCurrentSession(); if (currentSession != null) { JsonObject csrfTokenJsonObj = currentSession.getAttributes() .getJsonObject(SpincastFormsProtectionConfig.SESSION_VARIABLE_NAME_CSRF_TOKEN); if (csrfTokenJsonObj != null) { spincastCsrfToken = new SpincastCsrfToken(csrfTokenJsonObj.getString("id"), csrfTokenJsonObj.getInstant("creationDate")); } } //========================================== // Create a new token if required. // The token will be saved in the user's session... //========================================== if (spincastCsrfToken == null && createItIfNoneExists) { spincastCsrfToken = createCsrfToken(); currentSession.getAttributes().set(SpincastFormsProtectionConfig.SESSION_VARIABLE_NAME_CSRF_TOKEN, spincastCsrfToken); } return spincastCsrfToken; }
protected void addAlertsToModel() { if (isAddAlertsToModel()) { Map<String, Object> map = getRequestContext().templating().getSpincastReservedMap(); @SuppressWarnings("unchecked") List<Alert> alerts = (List<Alert>)map.get(SpincastConstants.TemplatingGlobalVariables.DEFAULT_GLOBAL_TEMPLATING_VAR_KEY_ALERTS); if (alerts != null && alerts.size() > 0) { JsonObject model = getModel(); String spincastModelObjKey = getSpincastConfig().getSpincastModelRootVariableName(); JsonObject spincastModelObj = model.getJsonObjectOrEmpty(spincastModelObjKey); model.set(spincastModelObjKey, spincastModelObj); JsonArray alertsArray = spincastModelObj.getJsonArrayOrEmpty(ResponseModelVariables.DEFAULT_RESPONSE_MODEL_VAR_ALERTS); spincastModelObj.set(ResponseModelVariables.DEFAULT_RESPONSE_MODEL_VAR_ALERTS, alertsArray); for (Alert alert : alerts) { alertsArray.add(alert); } } } }
@Override public void addForm(Form form, String validationElementName) { getModel().set(form.getFormName(), form); Object validationElementObj = getModel().getObject(validationElementName); if (validationElementObj == null) { validationElementObj = getJsonManager().create(); getModel().set(validationElementName, validationElementObj); } else if (!(validationElementObj instanceof JsonObject)) { throw new RuntimeException("The '" + validationElementName + "' element already exists on the response's model " + "but is not a JsonObject! It can't be used as the validation element : " + validationElementObj); } JsonObject validationElement = (JsonObject)validationElementObj; //========================================== // Tells the form to use that validation element // to strore validation messages. //========================================== form.setValidationObject(validationElement); }
jsonObject.set(name, deserialize(jsonParser, context)); jsonObject.set(name, getJsonArrayDeserializer().deserialize(jsonParser, context)); jsonObject.set(name, jsonParser.getEmbeddedObject()); jsonObject.set(name, null); jsonObject.set(name, jsonParser.getText()); jsonObject.set(name, true); jsonObject.set(name, false); jsonObject.set(name, jsonParser.getNumberValue());
@Override public String fromTemplate(String templatePath, boolean isClasspathPath, JsonObject model, Locale locale) { return fromTemplate(templatePath, isClasspathPath, (model != null ? model.convertToPlainMap() : null), locale); }
jsonObject.set(firstProperty.getKey(), firstProperty.getValue()); jsonObject.set(fieldName, getJsonManager().create()); } else if (token == JsonToken.START_OBJECT) { jsonObject.set(fieldName, deserializeObjectOrArray(xmlParser, context)); } else { Object value = xmlParser.readValueAs(Object.class); jsonObject.set(fieldName, getJsonManager().create()); } else { jsonObject.set(fieldName, value);
/** * Converts JsonObject and JsonArray to plain Maps and Lists. */ protected Object convertTemplatingGlobalVariableValue(Object value) { if (value != null) { if (value instanceof JsonObject) { value = ((JsonObject)value).convertToPlainMap(); } else if (value instanceof JsonArray) { value = ((JsonArray)value).convertToPlainList(); } } return value; }
jsonObject.set(fieldName, value);