use of act.inject.param.JsonDTO in project actframework by actframework.
the class ReflectedHandlerInvoker method ensureJsonDTOGenerated.
private void ensureJsonDTOGenerated(ActionContext context) {
if (0 == fieldsAndParamsCount || !context.jsonEncoded()) {
return;
}
Class<? extends JsonDTO> dtoClass = jsonDTOClassManager.get(controllerClass, method);
if (null == dtoClass) {
// there are neither fields nor params
return;
}
try {
JsonDTO dto = JSON.parseObject(patchedJsonBody(context), dtoClass);
cacheJsonDTO(context, dto);
} catch (JSONException e) {
if (e.getCause() != null) {
warn(e.getCause(), "error parsing JSON data");
} else {
warn(e, "error parsing JSON data");
}
throw new BadRequest(e.getCause());
}
}
use of act.inject.param.JsonDTO in project actframework by actframework.
the class FindBy method resolve.
private static String resolve(String bindName, ActContext ctx) {
String value = ctx.paramVal(bindName);
if (S.notEmpty(value)) {
return value;
}
if (ctx instanceof ActionContext) {
ActionContext actionContext = (ActionContext) ctx;
JsonDTO dto = actionContext.attribute(JsonDTO.CTX_ATTR_KEY);
if (null != dto) {
value = S.string(dto.get(bindName));
}
}
if (S.notEmpty(value)) {
return value;
}
Keyword keyword = Keyword.of(bindName);
if (keyword.tokens().size() > 1) {
return resolve(keyword, ctx);
} else {
keyword = Keyword.of(bindName + " id");
return resolve(keyword, ctx);
}
}
Aggregations