List of usage examples for com.fasterxml.jackson.databind.node JsonNodeFactory booleanNode
public BooleanNode booleanNode(boolean paramBoolean)
From source file:org.teavm.flavour.json.test.TeaVMJSONRunner.java
public static final JsonNode convert(JsonNodeFactory nf, Node node) { if (node.isNull()) { return nf.nullNode(); } else if (node.isBoolean()) { BooleanNode booleanNode = (BooleanNode) node; return nf.booleanNode(booleanNode.getValue()); } else if (node.isNumber()) { NumberNode numberNode = (NumberNode) node; if (numberNode.isInt()) { return nf.numberNode(numberNode.getIntValue()); } else {//from w w w . j ava 2 s.com return nf.numberNode(numberNode.getValue()); } } else if (node.isString()) { StringNode stringNode = (StringNode) node; return nf.textNode(stringNode.getValue()); } else if (node.isArray()) { ArrayNode result = nf.arrayNode(); org.teavm.flavour.json.tree.ArrayNode source = (org.teavm.flavour.json.tree.ArrayNode) node; for (int i = 0; i < source.size(); ++i) { result.add(convert(nf, source.get(i))); } return result; } else if (node.isObject()) { com.fasterxml.jackson.databind.node.ObjectNode result = nf.objectNode(); ObjectNode objectNode = (ObjectNode) node; for (String key : objectNode.allKeys()) { result.replace(key, convert(nf, objectNode.get(key))); } return result; } else { throw new IllegalArgumentException("Can't convert this JSON node"); } }
From source file:com.ikanow.aleph2.v1.document_db.utils.JsonNodeBsonUtils.java
/** Utility that goes from various MongoDB artefacts to JsonNode * @param x// ww w. j a v a 2 s. c o m * @return */ protected static JsonNode transform(Object x, JsonNodeFactory nc) { if (null == x) { // missing => missing return null; } else if (x instanceof ObjectId) { return nc.textNode(((ObjectId) x).toString()); } else if (x instanceof Boolean) { return nc.booleanNode(((Boolean) x)); } else if (x instanceof String) { return nc.textNode(((String) x)); } else if (x instanceof Date) { return nc.numberNode(((Date) x).getTime()); } else if (x instanceof Double) { return nc.numberNode(((Double) x)); } else if (x instanceof Float) { return nc.numberNode(((Float) x)); } else if (x instanceof Long) { return nc.numberNode(((Long) x)); } else if (x instanceof Integer) { return nc.numberNode(((Integer) x)); } else if (x instanceof byte[]) { return nc.binaryNode(((byte[]) x)); } else if (x instanceof BasicBSONList) { // (don't do this lazily, construct entire thing once requested) return new ArrayNodeWrapper(nc, (BasicBSONList) x); } else if (x instanceof BSONObject) { // recurse! (ish) return new ObjectNodeWrapper(nc, (BSONObject) x); } else return nc.nullNode(); }
From source file:com.ikanow.aleph2.search_service.elasticsearch.utils.JsonNodeWritableUtils.java
/** Utility that goes from Writable to JsonNode * @param x/*from ww w.j a v a 2s. c o m*/ * @return */ protected static JsonNode transform(Object x, JsonNodeFactory nc) { if (null == x) { return null; //(missing->missing) } else if (x instanceof NullWritable) { return nc.nullNode(); } else if (x instanceof BooleanWritable) { return nc.booleanNode(((BooleanWritable) x).get()); } else if (x instanceof Text) { return nc.textNode(((Text) x).toString()); } else if (x instanceof ByteWritable) { return nc.binaryNode(new byte[] { ((ByteWritable) x).get() }); } else if (x instanceof IntWritable) { return nc.numberNode(((IntWritable) x).get()); } else if (x instanceof VIntWritable) { return nc.numberNode(((VIntWritable) x).get()); } else if (x instanceof LongWritable) { return nc.numberNode(((LongWritable) x).get()); } else if (x instanceof VLongWritable) { return nc.numberNode(((VLongWritable) x).get()); } else if (x instanceof BytesWritable) { return nc.binaryNode(((BytesWritable) x).getBytes()); } else if (x instanceof DoubleWritable) { return nc.numberNode(((DoubleWritable) x).get()); } else if (x instanceof FloatWritable) { return nc.numberNode(((FloatWritable) x).get()); } else if (x instanceof ArrayWritable) { Writable[] xx = ((ArrayWritable) x).get(); // (don't do this lazily, construct entire thing once requested) return new ArrayNodeWrapper(nc, xx); } else if (x instanceof MapWritable) { // recurse! (ish) return new ObjectNodeWrapper(nc, (MapWritable) x); } else return nc.nullNode(); }
From source file:com.redhat.smonkey.RndBool.java
@Override public JsonNode generate(JsonNodeFactory nodeFactory, JsonNode data, Monkey mon) { boolean x = Utils.rnd.nextBoolean(); return nodeFactory.booleanNode(x); }
From source file:com.redhat.lightblue.metadata.types.BooleanType.java
@Override public JsonNode toJson(JsonNodeFactory factory, Object obj) { return factory.booleanNode((Boolean) cast(obj)); }
From source file:com.redhat.lightblue.metadata.rdbms.converter.RDBMSContext.java
@Override public String toString() { JsonNodeFactory jsonNodeFactory1 = jsonNodeFactory; if (jsonNodeFactory == null) { jsonNodeFactory1 = JsonNodeFactory.withExactBigDecimals(true); }/*from w ww .ja v a 2 s . c o m*/ ObjectNode objectNode = jsonNodeFactory1.objectNode(); NullNode nullNode = jsonNodeFactory1.nullNode(); String nullNodeString = JsonUtils.prettyPrint(nullNode); String s = null; JsonNode j = null; try { s = fromToQueryRange == null ? nullNodeString : fromToQueryRange.toString(); objectNode.set("fromToQueryRange", JsonUtils.json(s)); j = dataSource == null ? nullNode : jsonNodeFactory1.textNode(dataSource.toString()); objectNode.set("dataSource", j); j = dataSourceName == null ? nullNode : jsonNodeFactory1.textNode(dataSourceName.toString()); objectNode.set("dataSourceName", j); j = connection == null ? nullNode : jsonNodeFactory1.textNode(connection.toString()); objectNode.set("connection", j); j = preparedStatement == null ? nullNode : jsonNodeFactory1.textNode(preparedStatement.toString()); objectNode.set("preparedStatement", j); j = resultBoolean == null ? nullNode : jsonNodeFactory1.booleanNode(resultBoolean); objectNode.set("resultBoolean", j); j = resultInteger == null ? nullNode : jsonNodeFactory1.numberNode(resultInteger); objectNode.set("resultInteger", j); j = rowMapper == null ? nullNode : jsonNodeFactory1.textNode(rowMapper.toString()); objectNode.set("rowMapper", j); if (resultList != null) { ArrayNode jsonNodes = jsonNodeFactory1.arrayNode(); for (T a : resultList) { jsonNodes.add(a.toString()); } objectNode.set("resultList", jsonNodes); } else { objectNode.set("resultList", nullNode); } s = rdbms == null ? nullNodeString : rdbms.toString(); objectNode.set("rdbms", JsonUtils.json(s)); j = sql == null ? nullNode : jsonNodeFactory1.textNode(sql.toString()); objectNode.set("sql", j); j = type == null ? nullNode : jsonNodeFactory1.textNode(type.toString()); objectNode.set("type", j); j = entityMetadata == null ? nullNode : jsonNodeFactory1.textNode(entityMetadata.toString()); objectNode.set("entityMetadata", j); j = queryExpression == null ? nullNode : jsonNodeFactory1.textNode(queryExpression.toString()); objectNode.set("queryExpression", j); j = projection == null ? nullNode : jsonNodeFactory1.textNode(projection.toString()); objectNode.set("projection", j); j = sort == null ? nullNode : jsonNodeFactory1.textNode(sort.toString()); objectNode.set("sort", j); if (temporaryVariable != null) { ObjectNode jsonNodes = jsonNodeFactory1.objectNode(); for (Map.Entry<String, Object> a : temporaryVariable.entrySet()) { jsonNodes.set(a.getKey(), jsonNodeFactory1.textNode(a.getValue().toString())); } objectNode.set("temporaryVariable", jsonNodes); } else { objectNode.set("temporaryVariable", nullNode); } if (in != null) { ArrayNode jsonNodes = jsonNodeFactory1.arrayNode(); for (InOut a : in) { jsonNodes.add(a.toString()); } objectNode.set("in", jsonNodes); } else { objectNode.set("in", nullNode); } s = out == null ? nullNodeString : out.toString(); if (out != null) { ArrayNode jsonNodes = jsonNodeFactory1.arrayNode(); for (InOut a : out) { jsonNodes.add(a.toString()); } objectNode.set("out", jsonNodes); } else { objectNode.set("out", nullNode); } s = inVar == null ? nullNodeString : inVar.toString(); objectNode.set("inVar", JsonUtils.json(s)); s = outVar == null ? nullNodeString : outVar.toString(); objectNode.set("outVar", JsonUtils.json(s)); objectNode.set("initialInput", JsonUtils.json(Boolean.toString(initialInput))); if (inputMappedByField != null) { ObjectNode jsonNodes = jsonNodeFactory1.objectNode(); for (Map.Entry<String, Object> a : inputMappedByField.entrySet()) { jsonNodes.set(a.getKey(), jsonNodeFactory1.textNode(a.getValue().toString())); } objectNode.set("inputMappedByField", jsonNodes); } else { objectNode.set("inputMappedByField", nullNode); } if (inputMappedByColumn != null) { ObjectNode jsonNodes = jsonNodeFactory1.objectNode(); for (Map.Entry<String, Object> a : inputMappedByColumn.entrySet()) { jsonNodes.set(a.getKey(), jsonNodeFactory1.textNode(a.getValue().toString())); } objectNode.set("inputMappedByColumn", jsonNodes); } else { objectNode.set("inputMappedByColumn", nullNode); } s = jsonNodeFactory == null ? nullNodeString : jsonNodeFactory.toString(); objectNode.set("jsonNodeFactory", jsonNodeFactory1.textNode(s)); s = RDBMSDataSourceResolver == null ? nullNodeString : RDBMSDataSourceResolver.toString(); objectNode.set("RDBMSDataSourceResolver", JsonUtils.json(s)); s = fieldAccessRoleEvaluator == null ? nullNodeString : fieldAccessRoleEvaluator.toString(); objectNode.set("fieldAccessRoleEvaluator", jsonNodeFactory1.textNode(s)); s = CRUDOperationName == null ? nullNodeString : CRUDOperationName.toString(); objectNode.set("CRUDOperationName", jsonNodeFactory1.textNode(s)); s = crudOperationContext == null ? nullNodeString : crudOperationContext.toString(); objectNode.set("crudOperationContext", jsonNodeFactory1.textNode(s)); s = currentLoopOperator == null ? nullNodeString : currentLoopOperator.toString(); objectNode.set("currentLoopOperator", jsonNodeFactory1.textNode(s)); s = updateExpression == null ? nullNodeString : updateExpression.toString(); objectNode.set("updateExpression", jsonNodeFactory1.textNode(s)); } catch (IOException e) { throw new IllegalStateException(e); } return JsonUtils.prettyPrint(objectNode); }