Example usage for com.fasterxml.jackson.databind.node ObjectNode put

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode put

Introduction

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

Prototype

public ObjectNode put(String paramString1, String paramString2) 

Source Link

Usage

From source file:com.infinities.skyport.util.JsonUtil.java

public static String toJson(Throwable t) {
    ObjectNode root = getObjectMapper().createObjectNode();
    JsonNode empty = getObjectMapper().createObjectNode();
    root.put(JsonConstants.STATUS, 0).put(JsonConstants.MSG, t.getMessage()).put(JsonConstants._DATA, empty);

    try {//from   w  ww . j  a v  a 2  s .c  o  m
        return getObjectMapper().configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, false)
                .writeValueAsString(root);
    } catch (Exception e) {
        logger.error("json parsing failed", e);
        throw new RuntimeException(e);
    }
}

From source file:controllers.AjaxServices.java

public static Result getSimpleData() {
    ObjectNode result = Json.newObject();

    result.put("exchange_rates", Json.toJson(CurrencyRates.getActualExchangeRatesMap()));
    result.put("sellers", Json.toJson(SaleSeller.crossOptions()));

    return ok(result);
}

From source file:mobile.service.SelfInfoService.java

/**
 * ????/*from w w  w  .  j  a  v  a 2  s .  c om*/
 * 
 * @param jobExpArray
 * @return
 */
public static ServiceResult saveJobExp(ArrayNode jobExpArray) {
    ArrayNode newJobExpArray = jobExpArray.deepCopy();
    Iterator<JsonNode> elements = newJobExpArray.elements();
    while (elements.hasNext()) {
        ObjectNode next = (ObjectNode) elements.next();
        if (next.hasNonNull("endYear") && next.get("endYear").asText().equals("-1")) {
            next.put("endYear", "");
        }
    }

    ObjectNode jobExpNode = Json.newObject();
    jobExpNode.set("jobExp", newJobExpArray);
    ObjectNodeResult objectNodeResult = Expert.saveExpertByJson(Context.current().session(), jobExpNode);

    return ServiceResult.create(objectNodeResult);
}

From source file:controllers.contact.Contacts.java

public static Result investigation(Integer id) {
    Result hasProblem = AuthManager.hasProblem(RIGHT_SCOPE, RightLevel.Enable);
    if (hasProblem != null)
        return hasProblem;

    Contact contact = Contact.findById(id);

    List<Pair> properties = new ArrayList<Pair>();
    properties.add(new Pair(Messages.get("contact.relevant"), contact.relevant));
    properties.add(new Pair(Messages.get("phone"), contact.phone));
    properties.add(new Pair("Fax", contact.fax));
    properties.add(new Pair(Messages.get("mobile_phone"), contact.mobilePhone));
    properties.add(new Pair("Email", contact.email));
    properties.add(new Pair(Messages.get("contact.website"), contact.website));
    properties.add(Pair.EMPTY);/*from www  . j  a  va  2s .  co  m*/
    properties.add(new Pair(Messages.get("address") + " 1", contact.address1));
    properties.add(new Pair(Messages.get("address") + " 2", contact.address2));
    properties.add(new Pair(Messages.get("city"), contact.city));
    properties.add(Pair.EMPTY);
    properties.add(new Pair("TC Kimlik No", (contact.tcKimlik != null ? contact.tcKimlik.toString() : "")));
    properties.add(new Pair(Messages.get("contact.tax.no"), contact.taxNumber));
    properties.add(new Pair(Messages.get("contact.tax.office"), contact.taxOffice));

    ObjectNode result = Json.newObject();

    result.put("title", contact.name);
    result.put("body",
            investigation_form
                    .render(QueryUtils.inspectXTrans(Module.contact, contact.id),
                            QueryUtils.inspectXSummary(Module.contact, contact.id), properties, contact.note)
                    .body());

    return ok(result);
}

From source file:controllers.api.v1.Metric.java

public static Result updateMetric(int id) {
    ObjectNode result = Json.newObject();
    Map<String, String[]> params = request().body().asFormUrlEncoded();

    String message = MetricsDAO.updateMetricValues(id, params);
    if (StringUtils.isBlank(message)) {
        result.put("status", "success");
        return ok(result);
    } else {//from w  w  w  .j  a  v  a 2  s.c  om
        result.put("status", "failed");
        result.put("message", message);
        return badRequest(result);
    }

}

From source file:models.StockCategory.java

/**
 * Converts json tree what flat rows in database
 * //from  w w  w .  j  av a  2  s. c  om
 * There are many repeated code blocks which same of the each other in this method, fix it
 * 
 */
public static String listAllAsJson() {
    String result = CacheUtils.getValue(StockCategory.class, "listAll");
    if (result != null)
        return result;

    List<StockCategory> rootList = new ArrayList<StockCategory>();
    Map<Integer, List<StockCategory>> level1Map = new LinkedHashMap<Integer, List<StockCategory>>();
    Map<Integer, List<StockCategory>> level2Map = new LinkedHashMap<Integer, List<StockCategory>>();
    Map<Integer, List<StockCategory>> level3Map = new LinkedHashMap<Integer, List<StockCategory>>();
    Map<Integer, List<StockCategory>> level4Map = new LinkedHashMap<Integer, List<StockCategory>>();
    Map<Integer, List<StockCategory>> level5Map = new LinkedHashMap<Integer, List<StockCategory>>();

    List<StockCategory> codeList = find.where().eq("workspace", CacheUtils.getWorkspaceId()).orderBy("name")
            .findList();

    for (StockCategory item : codeList) {
        if (item.par5Id != null) {
            arrangeItems(level5Map, item, item.par5Id);
        } else if (item.par5Id == null && item.par4Id != null) {
            arrangeItems(level4Map, item, item.par4Id);
        } else if (item.par4Id == null && item.par3Id != null) {
            arrangeItems(level3Map, item, item.par3Id);
        } else if (item.par3Id == null && item.par2Id != null) {
            arrangeItems(level2Map, item, item.par2Id);
        } else if (item.par2Id == null && item.par1Id != null) {
            arrangeItems(level1Map, item, item.par1Id);
        } else if (item.par1Id == null) {
            rootList.add(item);
        }
    }

    /**
     * Root level
     */
    ArrayNode rootAN = Json.newObject().arrayNode();
    for (StockCategory rootItem : rootList) {
        ObjectNode itemRL = Json.newObject();
        itemRL.put("key", rootItem.id);
        itemRL.put("title", rootItem.name);
        if (level1Map.containsKey(rootItem.id)) {
            itemRL.put("isFolder", true);

            /**
             * Level 1
             */
            ArrayNode level1AN = Json.newObject().arrayNode();
            List<StockCategory> level1List = level1Map.get(rootItem.id);
            for (StockCategory level1Item : level1List) {
                ObjectNode item1L = Json.newObject();
                item1L.put("key", level1Item.id);
                item1L.put("title", level1Item.name);
                if (level2Map.containsKey(level1Item.id)) {
                    item1L.put("isFolder", true);

                    /**
                     * Level 2
                     */
                    ArrayNode level2AN = Json.newObject().arrayNode();
                    List<StockCategory> level2List = level2Map.get(level1Item.id);
                    for (StockCategory level2Item : level2List) {
                        ObjectNode item2L = Json.newObject();
                        item2L.put("key", level2Item.id);
                        item2L.put("title", level2Item.name);
                        if (level3Map.containsKey(level2Item.id)) {
                            item2L.put("isFolder", true);

                            /**
                             * Level 3
                             */
                            ArrayNode level3AN = Json.newObject().arrayNode();
                            List<StockCategory> level3List = level3Map.get(level2Item.id);
                            for (StockCategory level3Item : level3List) {
                                ObjectNode item3L = Json.newObject();
                                item3L.put("key", level3Item.id);
                                item3L.put("title", level3Item.name);
                                if (level4Map.containsKey(level3Item.id)) {
                                    item3L.put("isFolder", true);

                                    /**
                                     * Level 4
                                     */
                                    ArrayNode level4AN = Json.newObject().arrayNode();
                                    List<StockCategory> level4List = level4Map.get(level3Item.id);
                                    for (StockCategory level4Item : level4List) {
                                        ObjectNode item4L = Json.newObject();
                                        item4L.put("key", level4Item.id);
                                        item4L.put("title", level4Item.name);
                                        if (level5Map.containsKey(level4Item.id)) {
                                            item4L.put("isFolder", true);

                                            /**
                                             * Level 5
                                             */
                                            ArrayNode level5AN = Json.newObject().arrayNode();
                                            List<StockCategory> level5List = level5Map.get(level4Item.id);
                                            for (StockCategory level5Item : level5List) {
                                                ObjectNode item5L = Json.newObject();
                                                item5L.put("key", level5Item.id);
                                                item5L.put("title", level5Item.name);
                                                level5AN.add(item5L);
                                            }
                                            item4L.put("children", level5AN);
                                        }
                                        level4AN.add(item4L);
                                    }
                                    item3L.put("children", level4AN);
                                }
                                level3AN.add(item3L);
                            }
                            item2L.put("children", level3AN);
                        }
                        level2AN.add(item2L);
                    }
                    item1L.put("children", level2AN);
                }
                level1AN.add(item1L);
            }
            itemRL.put("children", level1AN);
        }
        rootAN.add(itemRL);
    }

    result = Json.stringify(rootAN);
    CacheUtils.setValue(StockCategory.class, "listAll", result);

    return result;
}

From source file:com.hpcloud.util.Serialization.java

/**
 * Returns {@code object} serialized to a JsonNode.
 * /*w  w  w. j a  v  a2s . c  o m*/
 * @throws RuntimeException if deserialization fails
 */
public static JsonNode toJsonNode(Object object) {
    try {
        ObjectNode rootNode = mapper.createObjectNode();
        JsonNode node = mapper.valueToTree(object);
        rootNode.put(rootNameFor(Types.deProxy(object.getClass())), node);
        return rootNode;
    } catch (Exception e) {
        throw Exceptions.uncheck(e, "Failed to serialize object: {}", object);
    }
}

From source file:models.GlobalPrivateCode.java

/**
 * Converts json tree what flat rows in database
 * /*w w w  .  j a va2  s .c om*/
 * There are many repeated code blocks which same of the each other in this method, fix it
 * 
 */
public static String listAllAsJson() {
    String result = CacheUtils.getValue(GlobalPrivateCode.class, "listAll");
    if (result != null)
        return result;

    List<GlobalPrivateCode> rootList = new ArrayList<GlobalPrivateCode>();
    Map<Integer, List<GlobalPrivateCode>> level1Map = new LinkedHashMap<Integer, List<GlobalPrivateCode>>();
    Map<Integer, List<GlobalPrivateCode>> level2Map = new LinkedHashMap<Integer, List<GlobalPrivateCode>>();
    Map<Integer, List<GlobalPrivateCode>> level3Map = new LinkedHashMap<Integer, List<GlobalPrivateCode>>();
    Map<Integer, List<GlobalPrivateCode>> level4Map = new LinkedHashMap<Integer, List<GlobalPrivateCode>>();
    Map<Integer, List<GlobalPrivateCode>> level5Map = new LinkedHashMap<Integer, List<GlobalPrivateCode>>();

    List<GlobalPrivateCode> codeList = find.where().eq("workspace", CacheUtils.getWorkspaceId()).orderBy("name")
            .findList();

    for (GlobalPrivateCode item : codeList) {
        if (item.par5Id != null) {
            arrangeItems(level5Map, item, item.par5Id);
        } else if (item.par5Id == null && item.par4Id != null) {
            arrangeItems(level4Map, item, item.par4Id);
        } else if (item.par4Id == null && item.par3Id != null) {
            arrangeItems(level3Map, item, item.par3Id);
        } else if (item.par3Id == null && item.par2Id != null) {
            arrangeItems(level2Map, item, item.par2Id);
        } else if (item.par2Id == null && item.par1Id != null) {
            arrangeItems(level1Map, item, item.par1Id);
        } else if (item.par1Id == null) {
            rootList.add(item);
        }
    }

    /**
     * Root level
     */
    ArrayNode rootAN = Json.newObject().arrayNode();
    for (GlobalPrivateCode rootItem : rootList) {
        ObjectNode itemRL = Json.newObject();
        itemRL.put("key", rootItem.id);
        itemRL.put("title", rootItem.name);
        if (level1Map.containsKey(rootItem.id)) {
            itemRL.put("isFolder", true);

            /**
             * Level 1
             */
            ArrayNode level1AN = Json.newObject().arrayNode();
            List<GlobalPrivateCode> level1List = level1Map.get(rootItem.id);
            for (GlobalPrivateCode level1Item : level1List) {
                ObjectNode item1L = Json.newObject();
                item1L.put("key", level1Item.id);
                item1L.put("title", level1Item.name);
                if (level2Map.containsKey(level1Item.id)) {
                    item1L.put("isFolder", true);

                    /**
                     * Level 2
                     */
                    ArrayNode level2AN = Json.newObject().arrayNode();
                    List<GlobalPrivateCode> level2List = level2Map.get(level1Item.id);
                    for (GlobalPrivateCode level2Item : level2List) {
                        ObjectNode item2L = Json.newObject();
                        item2L.put("key", level2Item.id);
                        item2L.put("title", level2Item.name);
                        if (level3Map.containsKey(level2Item.id)) {
                            item2L.put("isFolder", true);

                            /**
                             * Level 3
                             */
                            ArrayNode level3AN = Json.newObject().arrayNode();
                            List<GlobalPrivateCode> level3List = level3Map.get(level2Item.id);
                            for (GlobalPrivateCode level3Item : level3List) {
                                ObjectNode item3L = Json.newObject();
                                item3L.put("key", level3Item.id);
                                item3L.put("title", level3Item.name);
                                if (level4Map.containsKey(level3Item.id)) {
                                    item3L.put("isFolder", true);

                                    /**
                                     * Level 4
                                     */
                                    ArrayNode level4AN = Json.newObject().arrayNode();
                                    List<GlobalPrivateCode> level4List = level4Map.get(level3Item.id);
                                    for (GlobalPrivateCode level4Item : level4List) {
                                        ObjectNode item4L = Json.newObject();
                                        item4L.put("key", level4Item.id);
                                        item4L.put("title", level4Item.name);
                                        if (level5Map.containsKey(level4Item.id)) {
                                            item4L.put("isFolder", true);

                                            /**
                                             * Level 5
                                             */
                                            ArrayNode level5AN = Json.newObject().arrayNode();
                                            List<GlobalPrivateCode> level5List = level5Map.get(level4Item.id);
                                            for (GlobalPrivateCode level5Item : level5List) {
                                                ObjectNode item5L = Json.newObject();
                                                item5L.put("key", level5Item.id);
                                                item5L.put("title", level5Item.name);
                                                level5AN.add(item5L);
                                            }
                                            item4L.put("children", level5AN);
                                        }
                                        level4AN.add(item4L);
                                    }
                                    item3L.put("children", level4AN);
                                }
                                level3AN.add(item3L);
                            }
                            item2L.put("children", level3AN);
                        }
                        level2AN.add(item2L);
                    }
                    item1L.put("children", level2AN);
                }
                level1AN.add(item1L);
            }
            itemRL.put("children", level1AN);
        }
        rootAN.add(itemRL);
    }

    result = Json.stringify(rootAN);
    CacheUtils.setValue(GlobalPrivateCode.class, "listAll", result);

    return result;
}

From source file:models.GlobalTransPoint.java

/**
 * Converts json tree what flat rows in database
 * //from  w ww.ja va2  s  . c om
 * There are many repeated code blocks which same of the each other in this method, fix it
 * 
 */
public static String listAllAsJson() {
    String result = CacheUtils.getValue(GlobalTransPoint.class, "listAll");
    if (result != null)
        return result;

    List<GlobalTransPoint> rootList = new ArrayList<GlobalTransPoint>();
    Map<Integer, List<GlobalTransPoint>> level1Map = new LinkedHashMap<Integer, List<GlobalTransPoint>>();
    Map<Integer, List<GlobalTransPoint>> level2Map = new LinkedHashMap<Integer, List<GlobalTransPoint>>();
    Map<Integer, List<GlobalTransPoint>> level3Map = new LinkedHashMap<Integer, List<GlobalTransPoint>>();
    Map<Integer, List<GlobalTransPoint>> level4Map = new LinkedHashMap<Integer, List<GlobalTransPoint>>();
    Map<Integer, List<GlobalTransPoint>> level5Map = new LinkedHashMap<Integer, List<GlobalTransPoint>>();

    List<GlobalTransPoint> codeList = find.where().eq("workspace", CacheUtils.getWorkspaceId()).orderBy("name")
            .findList();

    for (GlobalTransPoint item : codeList) {
        if (item.par5Id != null) {
            arrangeItems(level5Map, item, item.par5Id);
        } else if (item.par5Id == null && item.par4Id != null) {
            arrangeItems(level4Map, item, item.par4Id);
        } else if (item.par4Id == null && item.par3Id != null) {
            arrangeItems(level3Map, item, item.par3Id);
        } else if (item.par3Id == null && item.par2Id != null) {
            arrangeItems(level2Map, item, item.par2Id);
        } else if (item.par2Id == null && item.par1Id != null) {
            arrangeItems(level1Map, item, item.par1Id);
        } else if (item.par1Id == null) {
            rootList.add(item);
        }
    }

    /**
     * Root level
     */
    ArrayNode rootAN = Json.newObject().arrayNode();
    for (GlobalTransPoint rootItem : rootList) {
        ObjectNode itemRL = Json.newObject();
        itemRL.put("key", rootItem.id);
        itemRL.put("title", rootItem.name);
        if (level1Map.containsKey(rootItem.id)) {
            itemRL.put("isFolder", true);

            /**
             * Level 1
             */
            ArrayNode level1AN = Json.newObject().arrayNode();
            List<GlobalTransPoint> level1List = level1Map.get(rootItem.id);
            for (GlobalTransPoint level1Item : level1List) {
                ObjectNode item1L = Json.newObject();
                item1L.put("key", level1Item.id);
                item1L.put("title", level1Item.name);
                if (level2Map.containsKey(level1Item.id)) {
                    item1L.put("isFolder", true);

                    /**
                     * Level 2
                     */
                    ArrayNode level2AN = Json.newObject().arrayNode();
                    List<GlobalTransPoint> level2List = level2Map.get(level1Item.id);
                    for (GlobalTransPoint level2Item : level2List) {
                        ObjectNode item2L = Json.newObject();
                        item2L.put("key", level2Item.id);
                        item2L.put("title", level2Item.name);
                        if (level3Map.containsKey(level2Item.id)) {
                            item2L.put("isFolder", true);

                            /**
                             * Level 3
                             */
                            ArrayNode level3AN = Json.newObject().arrayNode();
                            List<GlobalTransPoint> level3List = level3Map.get(level2Item.id);
                            for (GlobalTransPoint level3Item : level3List) {
                                ObjectNode item3L = Json.newObject();
                                item3L.put("key", level3Item.id);
                                item3L.put("title", level3Item.name);
                                if (level4Map.containsKey(level3Item.id)) {
                                    item3L.put("isFolder", true);

                                    /**
                                     * Level 4
                                     */
                                    ArrayNode level4AN = Json.newObject().arrayNode();
                                    List<GlobalTransPoint> level4List = level4Map.get(level3Item.id);
                                    for (GlobalTransPoint level4Item : level4List) {
                                        ObjectNode item4L = Json.newObject();
                                        item4L.put("key", level4Item.id);
                                        item4L.put("title", level4Item.name);
                                        if (level5Map.containsKey(level4Item.id)) {
                                            item4L.put("isFolder", true);

                                            /**
                                             * Level 5
                                             */
                                            ArrayNode level5AN = Json.newObject().arrayNode();
                                            List<GlobalTransPoint> level5List = level5Map.get(level4Item.id);
                                            for (GlobalTransPoint level5Item : level5List) {
                                                ObjectNode item5L = Json.newObject();
                                                item5L.put("key", level5Item.id);
                                                item5L.put("title", level5Item.name);
                                                level5AN.add(item5L);
                                            }
                                            item4L.put("children", level5AN);
                                        }
                                        level4AN.add(item4L);
                                    }
                                    item3L.put("children", level4AN);
                                }
                                level3AN.add(item3L);
                            }
                            item2L.put("children", level3AN);
                        }
                        level2AN.add(item2L);
                    }
                    item1L.put("children", level2AN);
                }
                level1AN.add(item1L);
            }
            itemRL.put("children", level1AN);
        }
        rootAN.add(itemRL);
    }

    result = Json.stringify(rootAN);
    CacheUtils.setValue(GlobalTransPoint.class, "listAll", result);

    return result;
}

From source file:org.opendaylight.nic.bgp.service.parser.BgpDataflowParser.java

public static String fromBgpDataFlow(final BgpDataflow bgpDataflow) {
    final ObjectMapper objectMapper = createObjectMapper();
    final ObjectNode ipv4NextHopNode = objectMapper.createObjectNode();
    final ObjectNode originNode = objectMapper.createObjectNode();
    final ObjectNode localPrefNode = objectMapper.createObjectNode();
    final ObjectNode asPathNode = objectMapper.createObjectNode();

    final ObjectNode attributesNode = objectMapper.createObjectNode();

    ipv4NextHopNode.put(GLOBAL, bgpDataflow.getGlobalIp().getValue());
    attributesNode.put(IPV4_NEXT_HOP, ipv4NextHopNode);
    attributesNode.put(AS_PATH, asPathNode);
    originNode.put(VALUE, ORIGIN_IGP);//from   w w  w . j ava  2s.c  o  m
    attributesNode.put(ORIGIN, originNode);
    localPrefNode.put(PREF, FIXED_PREF);
    attributesNode.put(LOCAL_PREF, localPrefNode);

    final ObjectNode ipv4RouteAttributesNode = objectMapper.createObjectNode();
    ipv4RouteAttributesNode.put(PREFIX, bgpDataflow.getPrefix().getValue());
    ipv4RouteAttributesNode.put(PATH_ID, bgpDataflow.getPathId());
    ipv4RouteAttributesNode.put(ATTRIBUTES, attributesNode);

    final ArrayNode arrayNode = objectMapper.createArrayNode();
    arrayNode.add(ipv4RouteAttributesNode);

    final ObjectNode ipv4RouteNode = objectMapper.createObjectNode();
    ipv4RouteNode.put(IPV4_ROUTE, arrayNode);

    final ObjectNode bgpInetIpv4Routes = objectMapper.createObjectNode();
    bgpInetIpv4Routes.put(BGP_INET_IPV4_ROUTES, ipv4RouteNode);

    return bgpInetIpv4Routes.toString();
}