APISonar


ninja.Results.json

> ninja > Results > json
ninja APIs Results APIs json APIs

Example 1
public Result getArticlesJson() {

        ArticlesDto articlesDto = articleDao.getAllArticles();

        return Results.json().render(articlesDto);

    }
Example 2
public Result postForm(Context context, FormObject formObject) {
        // formObject is parsed into the method
        // and rendered as json
        return Results.json().render(formObject);
    }
Example 3
public Result asyncEcho(final Context ctx) {
        executorService.schedule(new Runnable() {
            @Override
            public void run() {
                ctx.returnResultAsync(Results.json().render(ctx.getParameter("message")));

            }
        }, Long.parseLong(ctx.getParameter("timeout")), TimeUnit.MILLISECONDS);
        return Results.async();
    }
Example 4
public void testContentTypeGetsConvertedProperlyUponFinalize() {

        //init the context
        context.init(servletContext, httpServletRequest, httpServletResponse);

        //this must be Content-Type: application/json; encoding=utf-8
        Result result = Results.json();

        context.finalizeHeaders(result);

        verify(httpServletResponse).setCharacterEncoding(result.getCharset());
        verify(httpServletResponse).setContentType(result.getContentType());
    }
Example 5
public Result postArticleJson(@LoggedInUser String username,
                                  ArticleDto articleDto) {

        boolean succeeded = articleDao.postArticle(username, articleDto);

        if (!succeeded) {
            return Results.notFound();
        } else {
            return Results.json();
        }

    }
Example 6
public Result validation(@Param("email") @Required String email,
                             Validation validation) {

        if (validation.hasViolations()) {
            return Results.json()
                    .render(validation.getFieldViolations("email"));
        } else {
            return Results.json().render(email);
        }
    }
Example 7
public Result getArticleJson(@PathParam("id") Long id) {
    
        Article article = articleDao.getArticle(id);
        
        return Results.json().render(article);
    
    }
Example 8
public Result postFormWithFile(Context context, FormWithFile formObject, @Param("file") File file) {
        formObject.fileReceived = file != null ? file.exists() : Boolean.FALSE;
        return Results.json().render(formObject);
    }