use of com.liferay.apio.architect.message.json.JSONObjectBuilder in project com-liferay-apio-architect by liferay.
the class ErrorWriter method writeError.
/**
* Writes an {@link APIError} to a JSON object.
*
* @param errorMessageMapper the {@link ErrorMessageMapper} that matches
* the {@code apiError} and {@code httpHeaders} parameters
* @param apiError the API error
* @param httpHeaders the current request's HTTP headers
* @return the API error, as a JSON string
*/
public static String writeError(ErrorMessageMapper errorMessageMapper, APIError apiError, HttpHeaders httpHeaders) {
JSONObjectBuilder jsonObjectBuilder = new JSONObjectBuilder();
errorMessageMapper.onStart(jsonObjectBuilder, apiError, httpHeaders);
Optional<String> optional = apiError.getDescription();
optional.ifPresent(description -> errorMessageMapper.mapDescription(jsonObjectBuilder, description));
errorMessageMapper.mapStatusCode(jsonObjectBuilder, apiError.getStatusCode());
errorMessageMapper.mapTitle(jsonObjectBuilder, apiError.getTitle());
errorMessageMapper.mapType(jsonObjectBuilder, apiError.getType());
errorMessageMapper.onFinish(jsonObjectBuilder, apiError, httpHeaders);
JsonObject jsonObject = jsonObjectBuilder.build();
return jsonObject.toString();
}
use of com.liferay.apio.architect.message.json.JSONObjectBuilder in project com-liferay-apio-architect by liferay.
the class FormWriter method write.
/**
* Writes the {@link Form} to a string.
*
* @return the JSON representation of the {@code Form}
*/
public String write() {
JSONObjectBuilder jsonObjectBuilder = new JSONObjectBuilder();
_formMessageMapper.onStart(jsonObjectBuilder, _form, _requestInfo.getHttpHeaders());
String url = createFormURL(_requestInfo.getServerURL(), _form);
_formMessageMapper.mapFormURL(jsonObjectBuilder, url);
String title = _form.getTitle(_requestInfo.getLanguage());
_formMessageMapper.mapFormTitle(jsonObjectBuilder, title);
String description = _form.getDescription(_requestInfo.getLanguage());
_formMessageMapper.mapFormDescription(jsonObjectBuilder, description);
List<FormField> formFields = _form.getFormFields();
formFields.forEach(formField -> _formMessageMapper.mapFormField(jsonObjectBuilder, formField));
_formMessageMapper.onFinish(jsonObjectBuilder, _form, _requestInfo.getHttpHeaders());
JsonObject jsonObject = jsonObjectBuilder.build();
return jsonObject.toString();
}
Aggregations