當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjectNode.put方法代碼示例

本文整理匯總了Java中org.codehaus.jackson.node.ObjectNode.put方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectNode.put方法的具體用法?Java ObjectNode.put怎麽用?Java ObjectNode.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.codehaus.jackson.node.ObjectNode的用法示例。


在下文中一共展示了ObjectNode.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: countersToJSON

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
@Private
public JsonNode countersToJSON(Counters counters) {
  ObjectMapper mapper = new ObjectMapper();
  ArrayNode nodes = mapper.createArrayNode();
  if (counters != null) {
    for (CounterGroup counterGroup : counters) {
      ObjectNode groupNode = nodes.addObject();
      groupNode.put("NAME", counterGroup.getName());
      groupNode.put("DISPLAY_NAME", counterGroup.getDisplayName());
      ArrayNode countersNode = groupNode.putArray("COUNTERS");
      for (Counter counter : counterGroup) {
        ObjectNode counterNode = countersNode.addObject();
        counterNode.put("NAME", counter.getName());
        counterNode.put("DISPLAY_NAME", counter.getDisplayName());
        counterNode.put("VALUE", counter.getValue());
      }
    }
  }
  return nodes;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:21,代碼來源:JobHistoryEventHandler.java

示例2: doGet

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    PrintWriter out = resp.getWriter();
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode root = mapper.getNodeFactory().objectNode();

    HttpSession session = req.getSession(false);
    int orderId = (int)session.getAttribute("currentOrder");
    int userId = -1;
    if(orderId != -1){
        boolean success = (boolean)session.getAttribute("success");
        if(success){
            userId = (int)session.getAttribute("id_user");
        }
        OrderDBManager orderDBManager = new OrderDBManager();
        root.put("orderProperties",orderCollection(orderDBManager.get(orderId)));

    }
    root.put("currentUser",userId);
    root.put("order",orderId);
    out.append(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root));
    out.flush();
}
 
開發者ID:SergeyZhernovoy,項目名稱:Java-education,代碼行數:25,代碼來源:UpdateOrder.java

示例3: userAsJson

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
/**
 * Create a JSON with user details.
 *
 * @param user
 *            the user to process
 * @param xmlEncode
 *            whether characters that are reserved in XML should be encoded in the returned
 *            string
 * @return the JSON object as string
 */
public String userAsJson(UserData user, boolean xmlEncode) {
    // TODO should we handle the DELETED/REGISTERED status?
    ObjectMapper mapper = JsonHelper.getSharedObjectMapper();
    ObjectNode rootNode = mapper.getNodeFactory().objectNode();
    if (user != null) {
        // the attributes are the same as in REST API
        rootNode.put("alias", user.getAlias());
        rootNode.put("firstName", user.getFirstName());
        rootNode.put("lastName", user.getLastName());
        rootNode.put("userId", user.getId());
        rootNode.put("salutation", user.getSalutation());
    }
    String jsonString = JsonHelper.writeJsonTreeAsString(rootNode);
    if (xmlEncode) {
        jsonString = StringEscapeHelper.escapeXml(jsonString);
    }
    return jsonString;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:29,代碼來源:NoteTemplateTool.java

示例4: convert

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
public ArrayNode convert(Collection<Order> collection) {

        ArrayNode array = JsonNodeFactory.instance.arrayNode();
        for(Order param : collection){

            ObjectNode order = JsonNodeFactory.instance.objectNode();
            order.put("orderId", param.getId() );
            order.put("mile", param.getMilesage() );
            order.put("price", param.getPrice() );
            if(param.getSold()){
                order.put("sold", "V" );
            } else {
                order.put("sold", "" );
            }
            order.put("carName", param.getCar().getName() );
            order.put("carId", param.getCar().getId() );

            GregorianCalendar calendar = new GregorianCalendar();
            calendar.setTimeInMillis(param.getRelease().getTime());
            //calendar.get(Calendar.YEAR);

            order.put("data", String.valueOf(calendar.get(Calendar.YEAR)));
            order.put("userId", param.getUser().getId() );
            array.add(order);
        }
        return array;

    }
 
開發者ID:SergeyZhernovoy,項目名稱:Java-education,代碼行數:29,代碼來源:FilterOrder.java

示例5: createJsonNoteObjectFromAutosave

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
/**
 * Creates a JSON object with autosave data.
 *
 * @param noteId
 *            ID of the note
 * @param parentNoteId
 *            the ID of the parent note
 * @param repostNoteId
 *            Id of a possible repost note.
 * @param locale
 *            the locale of the current user
 * @param plaintextOnly
 *            true if the client expects the content in plaintext and not HTML
 * @return Response as JSON
 */
private ObjectNode createJsonNoteObjectFromAutosave(long noteId, long parentNoteId,
        long repostNoteId, Locale locale, boolean plaintextOnly) {
    Long nId = noteId < 0 ? null : noteId;
    Long parentId = parentNoteId < 0 ? null : parentNoteId;
    ArrayList<StringPropertyTO> properties = null;

    // add repost property if the repostNoteId is set
    if (repostNoteId >= 0) {
        properties = new ArrayList<>();
        properties.add(new StringPropertyTO(String.valueOf(repostNoteId),
                PropertyManagement.KEY_GROUP, RepostNoteStoringPreProcessor.KEY_ORIGIN_NOTE_ID,
                null));
    }
    AutosaveNoteData autosave = getNoteManagement().getAutosave(nId, parentId, properties,
            locale);
    if (autosave != null) {
        ObjectNode jsonObject = createJsonNoteObject(autosave, true, plaintextOnly);
        jsonObject.put("autosaveNoteId", autosave.getId());
        jsonObject.put("autosaveVersion", autosave.getVersion());
        jsonObject.put("crosspostBlogs", extractCrosspostBlogs(autosave));
        return jsonObject;
    }
    return null;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:40,代碼來源:CreateNoteWidget.java

示例6: createNotePropertyFilter

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
public static Object createNotePropertyFilter(String keyGroup, String key, String value,
        PropertyFilter.MatchMode matchMode, boolean negate) {
    ObjectNode propsObj = JsonHelper.getSharedObjectMapper().createObjectNode();
    propsObj.put("name", "npf");
    ArrayNode filterData = propsObj.putArray("value");
    filterData.add("Note");
    filterData.add(keyGroup);
    filterData.add(key);
    filterData.add(value);
    filterData.add(matchMode.name());
    // negation flag is optional
    if (negate) {
        filterData.add(true);
    }
    return propsObj;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:17,代碼來源:EmbedController.java

示例7: postRealTimeData

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
public static boolean postRealTimeData(HttpClient client, String url, String deviceToken) throws ParseException, IOException {
  HttpPost post = new HttpPost(url);
  post.addHeader("Cookie", Constants.X_SMS_AUTH_TOKEN + "=" + deviceToken);

  long MINS_AHEAD = 1000 * 60 * 30;   // Pretend we have 30 minutes of print time left
  int jobsInQueue = 6;                // and 6 jobs left in the queue
  String status = "DS_PRINTING";      // and we're currently printing

  Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
  Timestamp printCompleteTime = new Timestamp(cal.getTime().getTime() + MINS_AHEAD);
  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
  String date = format.format(printCompleteTime.getTime());

  ObjectMapper mapper = new org.codehaus.jackson.map.ObjectMapper();
  ObjectNode jsonNode = mapper.createObjectNode();

  jsonNode.put("deviceStatus", status);
  jsonNode.put("totalJobs", jobsInQueue);
  jsonNode.put("printTimeComplete", date);

  StringEntity entity = new StringEntity(jsonNode.toString());
  post.setEntity(entity);

  HttpResponse response = HttpClientWrapper.executeHttpCommand(client, post);
  if (response != null) {
    if (response.getStatusLine().getStatusCode() != 204) {
      HttpClientWrapper.logErrorResponse(response, "Failed To post data");
      return false;
    } else {
      EntityUtils.consumeQuietly(response.getEntity());
      log.info("Sucessfully posted data");
      System.out.println("Successfully posted data.");
      return false;
    }
  } else {
    log.error("No response returned from post data");
    return false;
  }
}
 
開發者ID:HPInc,項目名稱:printos-device-api-example-java,代碼行數:40,代碼來源:Device.java

示例8: getAppList

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
public static String getAppList(String sessionId) throws IOException {

        if (sessionId == null || sessionId.isEmpty())
            throw new IllegalArgumentException("Session Id is empty. Please login.");

        ObjectMapper m = new ObjectMapper();
        ObjectNode o = m.createObjectNode();
        o.put("SessionID",sessionId);
        StringEntity inputApps = new StringEntity(o.toString());
        return postSGDS("GetAppsList", inputApps);
    }
 
開發者ID:skygiraffe,項目名稱:skygiraffe-slackbot,代碼行數:12,代碼來源:SGDSClient.java

示例9: createEntitySearchJSONResult

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
/**
 * Creates an array of JSON objects which hold details about the found users or groups.
 * 
 * @param list
 *            the search result to process
 * @param addSummary
 *            if true a summary JSON object will be added to the top of the array. The JSON
 *            object will be created with {@link #createSearchSummaryStatement(PageableList)} .
 * @param imageSize
 *            the size of the user logo to include in the image path, can be null to not include
 *            the image path into the JSON object. For groups no image will be included.
 * @return the JSON array with the details about the users
 */
public static ArrayNode createEntitySearchJSONResult(
        PageableList<CommunoteEntityData> list, boolean addSummary,
        ImageSizeType imageSize) {
    JsonNodeFactory nodeFactory = JsonHelper.getSharedObjectMapper()
            .getNodeFactory();
    ArrayNode result = nodeFactory.arrayNode();
    if (addSummary) {
        result.add(UserSearchHelper.createSearchSummaryStatement(list));
    }
    for (CommunoteEntityData item : list) {
        String imagePath = null;
        boolean isGroup = (item instanceof EntityGroupListItem);
        if (!isGroup && imageSize != null) {
            imagePath = ImageUrlHelper.buildUserImageUrl(item.getEntityId(), imageSize);
        }
        ObjectNode entry = createUserSearchJSONResult(item.getEntityId(),
                item.getShortDisplayName(), item.getDisplayName(),
                imagePath, item.getAlias());
        entry.put("isGroup", isGroup);
        result.add(entry);
    }
    return result;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:37,代碼來源:UserSearchHelper.java

示例10: deleteAccount

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
/**
 * Deletion of the current user account.
 *
 * @param request
 *            the servlet request
 * @param response
 *            the servlet response
 *
 * @throws IOException
 *             in case of a IO error
 */
public void deleteAccount(HttpServletRequest request, HttpServletResponse response)
        throws IOException {

    ObjectNode jsonResponse = JsonHelper.getSharedObjectMapper().createObjectNode();
    String errorMessage = null;
    String mode = getDeleteMode(request);
    if (mode == null) {
        errorMessage = MessageHelper.getText(request, "user.delete.account.failed");
    } else {
        errorMessage = doDeleteAccount(request, mode);
    }
    if (errorMessage != null) {
        jsonResponse.put("message", errorMessage);
        jsonResponse.put("status", ApiResult.ResultStatus.ERROR.name());
    } else {
        // log user out
        AuthenticationHelper.removeAuthentication();
        jsonResponse.put("status", ApiResult.ResultStatus.OK.name());
    }
    JsonHelper.writeJsonTree(response.getWriter(), jsonResponse);
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:33,代碼來源:UserProfileActionController.java

示例11: convertToSamzaMessage

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
@Override
public KV<Object, Object> convertToSamzaMessage(SamzaSqlRelMessage relMessage) {

  String jsonValue;
  ObjectNode node = mapper.createObjectNode();

  List<String> fieldNames = relMessage.getFieldNames();
  List<Object> values = relMessage.getFieldValues();

  for (int index = 0; index < fieldNames.size(); index++) {
    Object value = values.get(index);
    if (value == null) {
      continue;
    }

    // TODO limited support right now.
    if (Long.class.isAssignableFrom(value.getClass())) {
      node.put(fieldNames.get(index), (Long) value);
    } else if (Integer.class.isAssignableFrom(value.getClass())) {
      node.put(fieldNames.get(index), (Integer) value);
    } else if (Double.class.isAssignableFrom(value.getClass())) {
      node.put(fieldNames.get(index), (Double) value);
    } else if (String.class.isAssignableFrom(value.getClass())) {
      node.put(fieldNames.get(index), (String) value);
    } else {
      node.put(fieldNames.get(index), value.toString());
    }
  }
  try {
    jsonValue = mapper.writeValueAsString(node);
  } catch (IOException e) {
    throw new SamzaException("Error json serializing object", e);
  }

  return new KV<>(relMessage.getKey(), jsonValue.getBytes());
}
 
開發者ID:srinipunuru,項目名稱:samza-sql-tools,代碼行數:37,代碼來源:JsonRelConverterFactory.java

示例12: setScaleSettings

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
/**
 * Set the scale settings of this type descriptor.
 *
 * @param verticalAlignment
 *            a value which describes the vertical alignment of the image within the background
 *            when it is scaled. A value of less than 0 means to place the image at the top
 *            edge, a value of 0 leads to centering the image and a value greater than 0 means
 *            to place the image at the bottom edge. Null can be used to reset this setting the
 *            default value.
 * @param horizontalAlignment
 *            a value which describes the horizontal alignment of the image within the
 *            background when it is scaled. A value of less than 0 means to place the image at
 *            the top left, a value of 0 leads to centering the image and a value greater than 0
 *            means to place the image at the right edge. Null can be used to reset this setting
 *            the default value.
 * @param backgroundColor
 *            the background color to use to fill unoccupied pixels when scaling an image. Null
 *            can be used to reset this setting the default value.
 */
public void setScaleSettings(Integer verticalAlignment, Integer horizontalAlignment,
        Color backgroundColor) {
    if (this.customizationHoldingProperty == null) {
        return;
    }
    String propertyValue;
    if (verticalAlignment == null && horizontalAlignment == null && backgroundColor == null) {
        propertyValue = null;
    } else {
        ObjectNode node = JsonHelper.getSharedObjectMapper().createObjectNode();
        if (verticalAlignment != null) {
            node.put(SETTING_JSON_FIELD_VALIGN,
                    normalizeAlignement(verticalAlignment.intValue()));
        }
        if (horizontalAlignment != null) {
            node.put(SETTING_JSON_FIELD_HALIGN,
                    normalizeAlignement(horizontalAlignment.intValue()));
        }
        if (backgroundColor != null) {
            node.put(SETTING_JSON_FIELD_COLOR,
                    ColorUtils.encodeRGBHexString(backgroundColor, true));
        }
        propertyValue = JsonHelper.writeJsonTreeAsString(node);
        if (propertyValue.isEmpty()) {
            propertyValue = null;
        }
    }
    if (!StringUtils.equals(customizationPropertyValue, propertyValue)) {
        getConfigurationManager().updateClientConfigurationProperty(
                customizationHoldingProperty, propertyValue);
        ImageManager imageManager = ServiceLocator.findService(ImageManager.class);
        imageManager.imageChanged(getName(), null, null);
        imageManager.defaultImageChanged(getName(), null);
    }
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:55,代碼來源:CustomizableImageTypeDescriptor.java

示例13: startSynchronization

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
/**
 * This method starts the synchronization and returns a JSON response.
 *
 * @param request
 *            The request.
 * @param response
 *            The response.
 * @throws IOException
 *             in case writing the JSON response failed
 *
 */
public void startSynchronization(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    TaskManagement taskManagement = ServiceLocator.instance().getService(TaskManagement.class);

    // do not run on clients other than the global to avoid DOS attacks
    // (because the job runs through all clients)
    String message = null;
    ObjectNode jsonResponse = JsonHelper.getSharedObjectMapper().createObjectNode();
    if (ClientHelper.isCurrentClientGlobal()) {
        try {
            CommunoteRuntime
                    .getInstance()
                    .getConfigurationManager()
                    .updateClientConfigurationProperty(
                            ClientProperty.GROUP_SYNCHRONIZATION_DO_FULL_SYNC,
                            Boolean.TRUE.toString());
            taskManagement.rescheduleTask("SynchronizeGroups", new Date());
            message = MessageHelper.getText(request,
                    "client.user.group.management.sync.start.success");
            jsonResponse.put("status", ApiResult.ResultStatus.OK.name());
        } catch (TaskStatusException e) {
            jsonResponse.put("status", ApiResult.ResultStatus.ERROR.name());
            if (TaskStatus.RUNNING.equals(e.getActualStatus())) {
                message = MessageHelper.getText(request,
                        "client.user.group.management.sync.start.error.running");
            } else {
                message = MessageHelper.getText(request,
                        "client.user.group.management.sync.start.error.failed");
            }
        }
    } else {
        jsonResponse.put("status", ApiResult.ResultStatus.ERROR.name());
        message = "Not supported!";
    }
    jsonResponse.put("message", message);
    JsonHelper.writeJsonTree(response.getWriter(), jsonResponse);
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:49,代碼來源:ClientUserGroupManagementController.java

示例14: getParameterList

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
public static String getParameterList(String sessionId, String appId, String repId, String repUpId) throws IOException {

        //
        if (sessionId == null || sessionId.isEmpty())
            throw new IllegalArgumentException("Session Id is empty. Please login.");

        HttpPost postRequest = new HttpPost("https://wspublisherv2https.skygiraffe.com/WSPublisherV2.svc/GetReport_ParametersMainScreen4");

        // add header
        postRequest.setHeader("Content-Type", "application/json");

        JsonNodeFactory f = JsonNodeFactory.instance;

        ObjectNode o = f.objectNode();

        o.put("ApplicationID", appId);
        o.put("ReportID", repId);
        o.put("TabID","");

        ArrayNode diuId = f.arrayNode();
        diuId = o.putArray("DataItemUpdateIDs");
        o.put("ReportUpdateID",repUpId);
        o.put("RequestID",sessionId);

        o.put("SessionID",sessionId);

        StringEntity inputApps = new StringEntity(o.toString());

        inputApps.setContentType("application/json");
        postRequest.setEntity(inputApps);

        CloseableHttpResponse responseParams = getHttpClient().execute(postRequest);
        String paramStr = "";
        try {
            HttpEntity entityApps = responseParams.getEntity();
            paramStr = EntityUtils.toString(entityApps, "UTF-8");
            EntityUtils.consume(entityApps);
        }finally{
            responseParams.close();
        }
        logger.debug("Params = "+paramStr);
        return paramStr;
    }
 
開發者ID:skygiraffe,項目名稱:skygiraffe-slackbot,代碼行數:44,代碼來源:SGDSClient.java

示例15: formatColumns

import org.codehaus.jackson.node.ObjectNode; //導入方法依賴的package包/類
private ObjectNode formatColumns(RowInfo row) throws CharacterCodingException {
    final ObjectNode columns = objectMapper.createObjectNode();
    for (CellInfo cell : row) {
        columns.put(cell.getName(), cell.getValueAsString());
    }
    return columns;
}
 
開發者ID:jmnarloch,項目名稱:cassandra-kafka-log,代碼行數:8,代碼來源:JacksonFormatter.java


注:本文中的org.codehaus.jackson.node.ObjectNode.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。