List of usage examples for com.fasterxml.jackson.databind JsonNode asText
public abstract String asText();
From source file:fr.gouv.vitam.query.parser.EsQueryParser.java
private static final Object getAsObject(JsonNode value) { if (value.isBoolean()) { return value.asBoolean(); } else if (value.canConvertToLong()) { return value.asLong(); } else if (value.isDouble()) { return value.asDouble(); } else {//from w w w . java 2 s . c o m return value.asText(); } }
From source file:la.alsocan.jsonshapeshifter.bindings.StringNodeBinding.java
@Override protected String readValue(JsonNode node) { return node.asText(); }
From source file:io.sqp.schemamatcher.fieldmatchers.StringFieldMatcher.java
@Override protected boolean otherFieldIsLessRestrictive(JsonNode field, JsonNode otherField) { return field.asText().equals(otherField.asText()); }
From source file:com.aol.one.patch.testobj.PatchableList.java
@Override public void addValue(String key, JsonNode value) { this.add(Integer.parseInt(key), value.asText()); }
From source file:org.jmingo.mapping.convert.mongo.type.deserialize.ObjectIdDeserializer.java
private ObjectId getAsObjectId(JsonNode treeNode) { String text = treeNode.asText(); boolean valide = ObjectId.isValid(text); if (!valide) { throw new RuntimeException("failed to create ObjectId from: " + text); }// w w w . ja v a 2s . c om return new ObjectId(text); }
From source file:com.ikanow.aleph2.data_model.utils.JsonUtils.java
/** Converts (possibly recursively) a JsonNode to its Java equivalent * @param to_convert - the JsonNode to convert to... * @return - ...a Java primitive, or Map<String, Object>, or List<Object> (where Object is a java type) *//* w w w. ja v a 2s .co m*/ public static Object jacksonToJava(final JsonNode to_convert) { final JsonNodeType type = to_convert.getNodeType(); // (we'll go old school for this...) switch (type) { case ARRAY: return Optionals.streamOf(to_convert.elements(), false).map(j -> jacksonToJava(j)) .collect(Collectors.toList()); case BINARY: try { return to_convert.binaryValue(); } catch (IOException e) { return null; } case BOOLEAN: return to_convert.asBoolean(); case NUMBER: if (to_convert.isFloatingPointNumber()) { return to_convert.asDouble(); } else { return to_convert.asLong(); } case OBJECT: return _mapper.convertValue(to_convert, Map.class); case POJO: return ((POJONode) to_convert).getPojo(); case STRING: return to_convert.asText(); default: // (MISSING, NULL) return null; } }
From source file:com.flipkart.foxtrot.core.parsers.ElasticsearchMappingParser.java
private FieldType getFieldType(JsonNode jsonNode) { String type = jsonNode.asText(); return FieldType.valueOf(type.toUpperCase()); }
From source file:com.aol.one.patch.testobj.PatchChildTestObject.java
public void replaceStrField(JsonNode newValue) { this.strField = newValue.asText(); }
From source file:com.msopentech.odatajclient.engine.data.json.DOMTreeUtilsV4.java
public static void buildSubtree(final Element parent, final JsonNode node) { final String v4AnnotationPrefix = "@"; final Iterator<String> fieldNameItor = node.fieldNames(); final Iterator<JsonNode> nodeItor = node.elements(); while (nodeItor.hasNext()) { final JsonNode child = nodeItor.next(); final String name = fieldNameItor.hasNext() ? fieldNameItor.next() : ""; // no name? array item if (name.isEmpty()) { final Element element = parent.getOwnerDocument().createElementNS(ODataConstants.NS_DATASERVICES, ODataConstants.PREFIX_DATASERVICES + ODataConstants.ELEM_ELEMENT); parent.appendChild(element); if (child.isValueNode()) { if (child.isNull()) { element.setAttributeNS(ODataConstants.NS_METADATA, ODataConstants.ATTR_NULL, Boolean.toString(true)); } else { element.appendChild(parent.getOwnerDocument().createTextNode(child.asText())); }/* w ww.j a va 2s . c o m*/ } if (child.isContainerNode()) { buildSubtree(element, child); } } else if (!name.contains("@") && !ODataConstants.JSON_TYPE.equals(name)) { final Element property = parent.getOwnerDocument().createElementNS(ODataConstants.NS_DATASERVICES, ODataConstants.PREFIX_DATASERVICES + name); parent.appendChild(property); boolean typeSet = false; if (node.hasNonNull(name + "@" + ODataConstants.JSON_TYPE)) { property.setAttributeNS(ODataConstants.NS_METADATA, ODataConstants.ATTR_M_TYPE, node.get(name + "@" + ODataConstants.JSON_TYPE).textValue()); typeSet = true; } if (child.isNull()) { property.setAttributeNS(ODataConstants.NS_METADATA, ODataConstants.ATTR_NULL, Boolean.toString(true)); } else if (child.isValueNode()) { if (!typeSet) { if (child.isInt()) { property.setAttributeNS(ODataConstants.NS_METADATA, ODataConstants.ATTR_M_TYPE, EdmSimpleType.Int32.toString()); } if (child.isLong()) { property.setAttributeNS(ODataConstants.NS_METADATA, ODataConstants.ATTR_M_TYPE, EdmSimpleType.Int64.toString()); } if (child.isBigDecimal()) { property.setAttributeNS(ODataConstants.NS_METADATA, ODataConstants.ATTR_M_TYPE, EdmSimpleType.Decimal.toString()); } if (child.isDouble()) { property.setAttributeNS(ODataConstants.NS_METADATA, ODataConstants.ATTR_M_TYPE, EdmSimpleType.Double.toString()); } if (child.isBoolean()) { property.setAttributeNS(ODataConstants.NS_METADATA, ODataConstants.ATTR_M_TYPE, EdmSimpleType.Boolean.toString()); } if (child.isTextual()) { property.setAttributeNS(ODataConstants.NS_METADATA, ODataConstants.ATTR_M_TYPE, EdmSimpleType.String.toString()); } } property.appendChild(parent.getOwnerDocument().createTextNode(child.asText())); } else if (child.isContainerNode()) { if (!typeSet && child.hasNonNull(v4AnnotationPrefix + ODataConstants.JSON_TYPE)) { property.setAttributeNS(ODataConstants.NS_METADATA, ODataConstants.ATTR_M_TYPE, child.get(v4AnnotationPrefix + ODataConstants.JSON_TYPE).textValue()); } final String type = property.getAttribute(ODataConstants.ATTR_M_TYPE); if (StringUtils.isNotBlank(type) && EdmSimpleType.isGeospatial(type)) { if (EdmSimpleType.Geography.toString().equals(type) || EdmSimpleType.Geometry.toString().equals(type)) { final String geoType = child.get(ODataConstants.ATTR_TYPE).textValue(); property.setAttributeNS(ODataConstants.NS_METADATA, ODataConstants.ATTR_M_TYPE, geoType.startsWith("Geo") ? EdmSimpleType.namespace() + "." + geoType : type + geoType); } if (child.has(ODataConstants.JSON_COORDINATES) || child.has(ODataConstants.JSON_GEOMETRIES)) { GeospatialJSONHandler.deserialize(child, property, property.getAttribute(ODataConstants.ATTR_M_TYPE)); } } else { buildSubtree(property, child); } } } } }
From source file:org.openmhealth.schema.pojos.serialize.dates.ISODateDeserializer.java
@Override public DateTime deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); return formatter.parseDateTime(node.asText()); }