/** * 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; }
@Override public void serialize(JsonArray jsonArray, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { if (jsonArray == null) { return; } List<Object> asList = jsonArray.convertToPlainList(); gen.writeObject(asList); } };
@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); } };
@Override public JsonObject getModel() { if (this.responseModel == null) { this.responseModel = getJsonManager().create(); } return this.responseModel; }
@Override public JsonArray fromListArray(List<?> elements) { if (elements == null) { return null; } JsonArray array = createArray(); if (elements != null) { for (Object element : elements) { array.add(element); } } return array; }
@Override public Object getElementAtJsonPath(JsonObject obj, String jsonPath) { return getJsonPathUtils().getElementAtJsonPath(obj, jsonPath); }
@Override public void removeElementAtJsonPath(JsonObject obj, String jsonPath) { getJsonPathUtils().removeElementAtJsonPath(obj, jsonPath); }
@Override public boolean isElementExists(JsonObject obj, String jsonPath) { return getJsonPathUtils().isElementExists(obj, jsonPath); }
@Override public JsonArray createArray() { return getJsonObjectFactory().createArray(); }
@Override public JsonObject create() { return getJsonObjectFactory().create(); }
protected String getAttributesHash() { return DigestUtils.md5Hex(this.attributes.toJsonString()); }
@Override public void putElementAtJsonPath(JsonObjectOrArray objOrArray, String jsonPath, Object value, boolean clone) { if (clone) { value = clone(value); } getJsonPathUtils().putElementAtJsonPath(objOrArray, jsonPath, value); }
@Override public JsonArray enumsToFriendlyJsonArray(Enum<?>[] enumValues) { JsonArray arr = createArray(); if (enumValues == null || enumValues.length == 0) { return arr; } for (Enum<?> enumValue : enumValues) { arr.add(enumToFriendlyJsonObject(enumValue)); } return arr; }
@Override public String fromTemplate(String templatePath, boolean isClasspathPath, JsonObject model, Locale locale) { return fromTemplate(templatePath, isClasspathPath, (model != null ? model.convertToPlainMap() : null), locale); }
@Override public Object getElementAtJsonPath(JsonObject obj, String jsonPath, Object defaultValue) { return getJsonPathUtils().getElementAtJsonPath(obj, jsonPath, defaultValue); }
@Override public void removeElementAtJsonPath(JsonArray array, String jsonPath) { getJsonPathUtils().removeElementAtJsonPath(array, jsonPath); }
@Override public boolean isElementExists(JsonArray array, String jsonPath) { return getJsonPathUtils().isElementExists(array, jsonPath); }
@Override public Object getElementAtJsonPath(JsonArray array, String jsonPath) { return getJsonPathUtils().getElementAtJsonPath(array, jsonPath); }
@Override public Object getElementAtJsonPath(JsonArray array, String jsonPath, Object defaultValue) { return getJsonPathUtils().getElementAtJsonPath(array, jsonPath, defaultValue); }