Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.JsonNode


        if (!userRequest.admin) {
            return forbidden();
        }
        User userToEdit = User.findById(id);

        JsonNode node = request().body().asJson();

        if (node != null && node.get("description") != null && !node.get("description").equals("null")) {
            String description = node.get("description").asText();
            userToEdit.description = description;
            userToEdit.save();
            return ok();
        else {
            Map<String, List<String>> errors = new HashMap<String, List<String>>();
View Full Code Here


    public static Result submitUsers() {
        User userRequest = getLoggedUser();
        if (!userRequest.admin) {
            return forbidden();
        }
        JsonNode node = request().body().asJson();
        Iterator<Map.Entry<String, JsonNode>> iteratorMails = node.fields();
        while (iteratorMails.hasNext()) {
            Map.Entry<String, JsonNode> entry = iteratorMails.next();
            String mail = entry.getKey();
            boolean admin = entry.getValue().asBoolean();
            User user = User.findByEmail(mail);
View Full Code Here

    public static Result mailing(String status) {
        return mailing(Proposal.Status.fromValue(status));
    }

    public static Result mailing(Proposal.Status status) {
        JsonNode body = request().body().asJson();
        String subjet = body.get("subject").asText();
        String mailMarkdown = body.get("mail").asText();

        PegDownProcessor pegDownProcessor = new PegDownProcessor();
        String mailHtml = pegDownProcessor.markdownToHtml(mailMarkdown);

        Set<String> mailsOfSpeakers = new HashSet<String>();
View Full Code Here

    public static Result saveComment(Long idProposal) throws MalformedURLException {
        User user = getLoggedUser();
        Proposal proposal = Proposal.find.byId(idProposal);

        JsonNode node = request().body().asJson();
        String commentForm = null;
        boolean privateComment = false;
        if (node != null && node.get("comment") != null && !node.get("comment").equals("null")) {
            commentForm = node.get("comment").asText();
            if (user.admin && node.get("private") != null) {
                privateComment = node.get("private").asBoolean();
            }
        } else {
            Map<String, List<String>> errors = new HashMap<String, List<String>>();
            errors.put("comment", Collections.singletonList(Messages.get("error.required")));
            return badRequest(toJson(errors));
View Full Code Here

    public static Result saveReponse(Long idProposal, Long idComment) throws MalformedURLException {
        User user = getLoggedUser();
        Proposal proposal = Proposal.find.byId(idProposal);
        Comment question = Comment.find.byId(idComment);

        JsonNode node = request().body().asJson();
        String commentForm = null;
        boolean privateComment = false;
        Logger.debug("nose : {}", node.asText());
        if (node != null && node.get("comment") != null && !node.get("comment").equals("null")) {
            commentForm = node.get("comment").asText();
            if (user.admin && node.get("private") != null) {
                privateComment = node.get("private").asBoolean();
            }
        } else {
            Map<String, List<String>> errors = new HashMap<String, List<String>>();
            errors.put("commentR", Collections.singletonList(Messages.get("error.required")));
            return badRequest(toJson(errors));
View Full Code Here

    public static Result editComment(Long idProposal, Long idComment) throws MalformedURLException {
        User user = getLoggedUser();
        Proposal proposal = Proposal.find.byId(idProposal);
        Comment question = Comment.find.byId(idComment);

        JsonNode node = request().body().asJson();
        String commentForm = null;
        Logger.debug("nose : {}", node.asText());
        if (node != null && node.get("comment") != null && !node.get("comment").equals("null")) {
            commentForm = node.get("comment").asText();
        } else {
            Map<String, List<String>> errors = new HashMap<String, List<String>>();
            errors.put("commentE", Collections.singletonList(Messages.get("error.required")));
            return badRequest(toJson(errors));
        }
View Full Code Here

            return forbidden();
        }

        Proposal proposal = Proposal.find.byId(idProposal);

        JsonNode node = request().body().asJson();

        Proposal.Status newStatus = Proposal.Status.fromValue(node.get("status").asText());

        if (proposal.statusProposal != newStatus) {
            proposal.statusProposal = newStatus;

            proposal.save();
View Full Code Here

            for (String name : PathUtils.elements(path)) {
                tree = tree.addChild(name);
            }

            ObjectMapper mapper = new ObjectMapper();
            JsonNode node = mapper.readTree(request.getInputStream());
            if (node.isObject()) {
                post(node, tree);
                root.commit();
                doGet(request, response);
            } else {
                response.sendError(HttpServletResponse.SC_BAD_REQUEST);
View Full Code Here

    private static void post(JsonNode node, Tree tree) {
        Iterator<Entry<String, JsonNode>> iterator = node.fields();
        while (iterator.hasNext()) {
            Entry<String, JsonNode> entry = iterator.next();
            String name = entry.getKey();
            JsonNode value = entry.getValue();
            if (value.isObject()) {
                if (tree.hasProperty(name)) {
                    tree.removeProperty(name);
                }
                Tree child = tree.getChild(name);
                if (!child.exists()) {
                    child = tree.addChild(name);
                }
                post(value, child);
            } else {
                Tree child = tree.getChild(name);
                if (child.exists()) {
                    child.remove();
                }
                if (value.isNull()) {
                    tree.removeProperty(name);
                } else if (value.isBoolean()) {
                    tree.setProperty(name, value.asBoolean());
                } else if (value.isLong()) {
                    tree.setProperty(name, value.asLong());
                } else if (value.isDouble()) {
                    tree.setProperty(name, value.asDouble());
                } else if (value.isBigDecimal()) {
                    tree.setProperty(name, value.decimalValue());
                } else {
                    tree.setProperty(name, value.asText());
                }
            }
        }
    }
View Full Code Here

        assertThat(node.get("string-property").asText()).isEqualTo("string-value");
    }

    @Test
    public void strings_are_unwrapped() {
        JsonNode node = using(JACKSON_TREE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property");
        String unwrapped = using(JACKSON_TREE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.string-property", String.class);

        assertThat(unwrapped).isEqualTo("string-value");
        assertThat(unwrapped).isEqualTo(node.asText());
    }
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.databind.JsonNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.