Example usage for com.fasterxml.jackson.databind.node JsonNodeFactory instance

List of usage examples for com.fasterxml.jackson.databind.node JsonNodeFactory instance

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node JsonNodeFactory instance.

Prototype

JsonNodeFactory instance

To view the source code for com.fasterxml.jackson.databind.node JsonNodeFactory instance.

Click Source Link

Usage

From source file:controllers.CommentController.java

public Result getMentions(String email) {
    Long userId = userRepository.getUserIdByEmail(email);
    String username = userRepository.getUsernameByEmail(email);
    List<BigInteger> commentIds = mentionRepository.findAllCommentIdByUsername(username);
    ArrayNode commentArray = JsonNodeFactory.instance.arrayNode();
    Long total_comment = 0L;/*from  www  . jav a 2 s  .co  m*/

    ObjectNode response = Json.newObject();
    ObjectNode result = Json.newObject();
    ObjectNode user = Json.newObject();

    // User node
    if (userId == null) {
        user.put("user_id", -1);
        user.put("fullname", "Visitor");
        user.put("is_logged_in", false);
        user.put("is_add_allowed", false);
        user.put("is_edit_allowed", false);
    } else {
        user.put("user_id", userId);
        user.put("fullname", username);
        user.put("is_logged_in", true);
        user.put("is_add_allowed", true);
        user.put("is_edit_allowed", true);
    }
    user.put("picture", "/assets/images/user_blank_picture.png");

    for (BigInteger commentId : commentIds) {
        //Long commentId = ((BigInteger)commentIds[i]).longValue();
        Comment comment = commentRepository.findCommentById(commentId.longValue());

        ObjectNode oneComment = JsonNodeFactory.instance.objectNode();
        oneComment.put("comment_id", comment.getCommentId());
        oneComment.put("parent_id", 0);
        oneComment.put("in_reply_to", comment.getInReplyTo());
        oneComment.put("element_id", comment.getElementId());
        oneComment.put("created_by", comment.getCreatedBy());
        oneComment.put("fullname", comment.getFullname());
        oneComment.put("picture", comment.getPicture());
        oneComment.put("posted_date", timeFormat.format(comment.getPostedDate()));
        oneComment.put("text", comment.getText());
        oneComment.put("attachments", JsonNodeFactory.instance.arrayNode());
        oneComment.put("childrens", JsonNodeFactory.instance.arrayNode());
        commentArray.add(oneComment);
        total_comment++;
    }

    // result
    result.put("comments", commentArray);
    result.put("total_comment", total_comment);
    result.put("user", user);

    // response
    response.put("results", result);

    return ok(response.toString());
}

From source file:org.jetbrains.webdemo.database.MySqlConnector.java

public String addProject(UserInfo userInfo, String name, String type) throws DatabaseOperationException {
    try {//from  ww  w  . j a v a  2s  .co  m
        String projectId = addProject(userInfo, new Project(name, "", "java"), type, null);
        String fileId = addFileToProject(userInfo, projectId, name, "fun main(args: Array<String>) {\n\n}");

        ObjectNode response = new ObjectNode(JsonNodeFactory.instance);
        response.put("projectId", projectId);
        response.put("fileId", fileId);
        return objectMapper.writeValueAsString(response);
    } catch (IOException e) {
        throw new DatabaseOperationException("IO exception");
    }
}

From source file:io.gs2.matchmaking.Gs2MatchmakingClient.java

/**
 * ??????<br>// w  w  w. j a  v  a2  s  . c  o m
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public CreateMatchmakingResult createMatchmaking(CreateMatchmakingRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("name", request.getName())
            .put("serviceClass", request.getServiceClass()).put("type", request.getType())
            .put("maxPlayer", request.getMaxPlayer());
    if (request.getDescription() != null)
        body.put("description", request.getDescription());
    if (request.getGatheringPoolName() != null)
        body.put("gatheringPoolName", request.getGatheringPoolName());
    if (request.getCallback() != null)
        body.put("callback", request.getCallback());
    if (request.getNotificationGameName() != null)
        body.put("notificationGameName", request.getNotificationGameName());
    if (request.getCreateGatheringTriggerScript() != null)
        body.put("createGatheringTriggerScript", request.getCreateGatheringTriggerScript());
    if (request.getCreateGatheringDoneTriggerScript() != null)
        body.put("createGatheringDoneTriggerScript", request.getCreateGatheringDoneTriggerScript());
    if (request.getJoinGatheringTriggerScript() != null)
        body.put("joinGatheringTriggerScript", request.getJoinGatheringTriggerScript());
    if (request.getJoinGatheringDoneTriggerScript() != null)
        body.put("joinGatheringDoneTriggerScript", request.getJoinGatheringDoneTriggerScript());
    if (request.getLeaveGatheringTriggerScript() != null)
        body.put("leaveGatheringTriggerScript", request.getLeaveGatheringTriggerScript());
    if (request.getLeaveGatheringDoneTriggerScript() != null)
        body.put("leaveGatheringDoneTriggerScript", request.getLeaveGatheringDoneTriggerScript());
    if (request.getBreakupGatheringTriggerScript() != null)
        body.put("breakupGatheringTriggerScript", request.getBreakupGatheringTriggerScript());
    if (request.getMatchmakingCompleteTriggerScript() != null)
        body.put("matchmakingCompleteTriggerScript", request.getMatchmakingCompleteTriggerScript());

    HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/matchmaking", credential, ENDPOINT,
            CreateMatchmakingRequest.Constant.MODULE, CreateMatchmakingRequest.Constant.FUNCTION,
            body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(post, CreateMatchmakingResult.class);

}

From source file:io.gs2.inbox.Gs2InboxClient.java

/**
 * ????<br>/*from w w w.  j av a2s . co  m*/
 * <br>
 * - : 10<br>
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public ReadMessageResult readMessage(ReadMessageRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode();

    HttpPost post = createHttpPost(
            Gs2Constant.ENDPOINT_HOST + "/inbox/"
                    + (request.getInboxName() == null || request.getInboxName().equals("") ? "null"
                            : request.getInboxName())
                    + "/message/"
                    + (request.getMessageId() == null || request.getMessageId().equals("") ? "null"
                            : request.getMessageId())
                    + "",
            credential, ENDPOINT, ReadMessageRequest.Constant.MODULE, ReadMessageRequest.Constant.FUNCTION,
            body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    post.setHeader("X-GS2-ACCESS-TOKEN", request.getAccessToken());

    return doRequest(post, ReadMessageResult.class);

}

From source file:org.apache.usergrid.client.EntityTestCase.java

@Test
public void testEntityAppendInArray() {
    String collectionName = "testEntityProperties" + System.currentTimeMillis();
    String entityName = "testEntity1";

    UsergridEntity entity = new UsergridEntity(collectionName, entityName);
    entity.save();/*ww w.  j a va  2s.  co m*/

    ArrayList<Object> lenArr = new ArrayList<>();
    lenArr.add(1);
    lenArr.add(2);
    lenArr.add(3);
    lenArr.add(4);
    entity.insert("lenArray", lenArr);
    entity.save();

    lenArr = new ArrayList<>();
    lenArr.add(6);
    lenArr.add(7);
    entity.append("lenArray", lenArr);
    entity.save();

    UsergridEntity eLookUp = Usergrid.GET(collectionName, entityName).first();
    assertNotNull("The entity returned is not null.", eLookUp);

    ArrayNode toCompare = new ArrayNode(JsonNodeFactory.instance);
    toCompare.add(1).add(2).add(3).add(4).add(6).add(7);
    assertEquals("The two arrays should be equal.", eLookUp.getJsonNodeProperty("lenArray"), toCompare);
}

From source file:org.jetbrains.webdemo.database.MySqlConnector.java

public String addAdventOfCodeProject(UserInfo userInfo, String name, String inputFileContent)
        throws DatabaseOperationException {
    try {//www . j  ava  2s. co  m
        String projectId = addProject(userInfo, new Project(name, "", "java"), "ADVENT_OF_CODE_PROJECT", null);
        String fileId = addFileToProject(userInfo, projectId, name,
                "fun main(args: Array<String>) {\n//your input stored in the `input` variable\n}");
        String inputFileId = addFileToProject(userInfo, projectId, "Input.kt", inputFileContent);

        ObjectNode response = new ObjectNode(JsonNodeFactory.instance);
        response.put("projectId", projectId);
        response.put("fileId", fileId);
        response.put("inputFileId", inputFileId);
        return objectMapper.writeValueAsString(response);
    } catch (IOException e) {
        throw new DatabaseOperationException("IO exception");
    }
}

From source file:org.springframework.cloud.aws.messaging.listener.QueueMessageHandlerTest.java

@Test
public void receiveMessage_withNotificationMessageAndSubject_shouldResolveThem() throws Exception {
    // Arrange//w w w  . j  a  v a2s . com
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerSingleton("notificationMessageReceiver", NotificationMessageReceiver.class);
    applicationContext.registerSingleton("queueMessageHandler", QueueMessageHandler.class);
    applicationContext.refresh();

    QueueMessageHandler queueMessageHandler = applicationContext.getBean(QueueMessageHandler.class);
    NotificationMessageReceiver notificationMessageReceiver = applicationContext
            .getBean(NotificationMessageReceiver.class);

    ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
    jsonObject.put("Type", "Notification");
    jsonObject.put("Subject", "Hi!");
    jsonObject.put("Message", "Hello World!");
    String payload = jsonObject.toString();

    // Act
    queueMessageHandler.handleMessage(MessageBuilder.withPayload(payload)
            .setHeader(QueueMessageHandler.Headers.LOGICAL_RESOURCE_ID_MESSAGE_HEADER_KEY, "testQueue")
            .build());

    // Assert
    assertEquals("Hi!", notificationMessageReceiver.getSubject());
    assertEquals("Hello World!", notificationMessageReceiver.getMessage());
}

From source file:org.apache.usergrid.client.EntityTestCase.java

@Test
public void testEntityPrependInArray() {
    String collectionName = "testEntityProperties" + System.currentTimeMillis();
    String entityName = "testEntity1";

    UsergridEntity entity = new UsergridEntity(collectionName, entityName);
    entity.save();// w  w w  . ja  v a 2s  .c om

    ArrayList<Object> lenArr = new ArrayList<>();
    lenArr.add(1);
    lenArr.add(2);
    lenArr.add(3);
    lenArr.add(4);
    entity.putProperty("lenArray", lenArr);
    entity.save();

    lenArr = new ArrayList<>();
    lenArr.add(6);
    lenArr.add(7);

    entity.insert("lenArray", lenArr, 0);
    entity.save();
    UsergridEntity eLookUp = Usergrid.GET(collectionName, entityName).first();
    assertNotNull("The entity returned is not null.", eLookUp);

    ArrayNode toCompare = new ArrayNode(JsonNodeFactory.instance);
    toCompare.add(6).add(7).add(1).add(2).add(3).add(4);
    assertEquals("The two arrays should be equal.", eLookUp.getJsonNodeProperty("lenArray"), toCompare);
}

From source file:org.eel.kitchen.jsonschema.main.JsonSchemaFactory.java

/**
 * Create a schema from a container, at a certain path
 *
 * <p>For instance, if you register this schema:</p>
 *
 * <pre>/* ww w.  jav a2 s  .  c o  m*/
 *     {
 *         "schema1": { ... },
 *         "schema2": { ... }
 *     }
 * </pre>
 *
 * <p>then you can create a validator for {@code schema1} using:</p>
 *
 * <pre>
 *     final JsonSchema schema = factory.create(container, "#/schema1");
 * </pre>
 *
 * <p>The path can be a {@link JsonPointer} as above,
 * but also an id reference.</p>
 *
 * @param container the schema container
 * @param path the pointer/id reference into the schema
 * @return a {@link JsonSchema} instance
 *
 * @deprecated use {@link #fromSchema(JsonNode, String)} instead; scheduled
 * for removal in 1.3+
 */
@Deprecated
public JsonSchema createSchema(final SchemaContainer container, final String path) {
    final JsonNode node = JsonNodeFactory.instance.objectNode().put("$ref", path);

    return createSchema(container, node);
}

From source file:com.netflix.genie.web.controllers.JobRestController.java

/**
 * Get the status of the given job if it exists.
 *
 * @param id The id of the job to get status for
 * @return The status of the job as one of: {@link JobStatus}
 * @throws GenieException on error/* w w  w .ja  va 2 s .  co m*/
 */
@RequestMapping(value = "/{id}/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public JsonNode getJobStatus(@PathVariable("id") final String id) throws GenieException {
    log.debug("[getJobStatus] Called for job with id: {}", id);
    final JsonNodeFactory factory = JsonNodeFactory.instance;
    return factory.objectNode().set("status",
            factory.textNode(this.jobSearchService.getJobStatus(id).toString()));
}