Search in sources :

Example 1 with JsonDTO

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());
    }
}
Also used : BadRequest(org.osgl.mvc.result.BadRequest) JSONException(com.alibaba.fastjson.JSONException) JsonDTO(act.inject.param.JsonDTO)

Example 2 with JsonDTO

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);
    }
}
Also used : ActionContext(act.app.ActionContext) JsonDTO(act.inject.param.JsonDTO)

Aggregations

JsonDTO (act.inject.param.JsonDTO)2 ActionContext (act.app.ActionContext)1 JSONException (com.alibaba.fastjson.JSONException)1 BadRequest (org.osgl.mvc.result.BadRequest)1