List of usage examples for com.fasterxml.jackson.databind JsonNode textValue
public String textValue()
From source file:com.sitewhere.server.asset.scim.Wso2ScimAssetModule.java
/** * Parse name fields.// w w w .java 2 s . c o m * * @param resource * @param asset */ protected void parseName(JsonNode resource, PersonAsset asset) { JsonNode name = resource.get(IScimFields.NAME); if (name != null) { String full = ""; JsonNode given = name.get(IScimFields.GIVEN_NAME); if (given != null) { String givenValue = given.textValue(); full += givenValue + " "; asset.setProperty(IScimFields.GIVEN_NAME, givenValue); } JsonNode family = name.get(IScimFields.FAMILY_NAME); if (family != null) { String familyValue = family.textValue(); full += familyValue; asset.setProperty(IScimFields.FAMILY_NAME, familyValue); } asset.setProperty(IWso2ScimFields.PROP_NAME, full.trim()); } }
From source file:com.datamountaineer.streamreactor.connect.json.SimpleJsonConverterTest.java
@Test public void dateToJson() throws IOException { GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.add(Calendar.DATE, 10000); java.util.Date date = calendar.getTime(); JsonNode converted = converter.fromConnectData(Date.SCHEMA, date); assertTrue(converted.isTextual());//from w w w . ja v a 2 s. c o m assertEquals(SimpleJsonConverter.ISO_DATE_FORMAT.format(date), converted.textValue()); }
From source file:com.ottogroup.bi.spqr.operator.json.filter.JsonContentFilter.java
/** * Walks along the path provided and reads out the leaf value which is returned as string * @param jsonNode/* w w w . j av a 2 s .c o m*/ * @param fieldPath * @return */ protected String getTextFieldValue(final JsonNode jsonNode, final String[] fieldPath) { int fieldAccessStep = 0; JsonNode contentNode = jsonNode; while (fieldAccessStep < fieldPath.length) { contentNode = contentNode.get(fieldPath[fieldAccessStep]); fieldAccessStep++; } if (contentNode != null) return contentNode.textValue(); return ""; }
From source file:com.rusticisoftware.tincan.ActivityDefinition.java
public ActivityDefinition(JsonNode jsonNode) throws URISyntaxException { this();/*from w w w. ja va2 s.com*/ JsonNode typeNode = jsonNode.path("type"); if (!typeNode.isMissingNode()) { this.setType(new URI(typeNode.textValue())); } JsonNode moreInfoNode = jsonNode.path("moreInfo"); if (!moreInfoNode.isMissingNode()) { this.setMoreInfo(new URI(moreInfoNode.textValue())); } JsonNode nameNode = jsonNode.path("name"); if (!nameNode.isMissingNode()) { this.setName(new LanguageMap(nameNode)); } JsonNode descNode = jsonNode.path("description"); if (!descNode.isMissingNode()) { this.setDescription(new LanguageMap(descNode)); } JsonNode extensionsNode = jsonNode.path("extensions"); if (!extensionsNode.isMissingNode()) { this.setExtensions(new Extensions(extensionsNode)); } JsonNode interactionTypeNode = jsonNode.path("interactionType"); InteractionType intType = null; if (!interactionTypeNode.isMissingNode()) { intType = getByString(interactionTypeNode.textValue()); this.setInteractionType(intType); } JsonNode correctResponsesPatternNode = jsonNode.path("correctResponsesPattern"); if (!correctResponsesPatternNode.isMissingNode()) { this.correctResponsesPattern = new ArrayList<String>(); for (JsonNode element : correctResponsesPatternNode) { this.correctResponsesPattern.add(element.textValue()); } } JsonNode choicesNode = jsonNode.path("choices"); if (!choicesNode.isMissingNode()) { this.choices = new ArrayList<InteractionComponent>(); for (JsonNode element : choicesNode) { this.choices.add(new InteractionComponent(element)); } } JsonNode scaleNode = jsonNode.path("scale"); if (!scaleNode.isMissingNode()) { this.scale = new ArrayList<InteractionComponent>(); for (JsonNode element : scaleNode) { this.scale.add(new InteractionComponent(element)); } } JsonNode sourceNode = jsonNode.path("source"); if (!sourceNode.isMissingNode()) { this.source = new ArrayList<InteractionComponent>(); for (JsonNode element : sourceNode) { this.source.add(new InteractionComponent(element)); } } JsonNode targetNode = jsonNode.path("target"); if (!targetNode.isMissingNode()) { this.target = new ArrayList<InteractionComponent>(); for (JsonNode element : targetNode) { this.target.add(new InteractionComponent(element)); } } JsonNode stepsNode = jsonNode.path("steps"); if (!stepsNode.isMissingNode()) { this.steps = new ArrayList<InteractionComponent>(); for (JsonNode element : stepsNode) { this.steps.add(new InteractionComponent(element)); } } }
From source file:com.vz.onosproject.zeromqprovider.AppWebResource.java
/** * Installs flows to downstream ZMQ device * @param stream blob flowrule//from w w w. j a v a2 s .c om * @return 200 OK */ @POST @Path("flows") @Consumes(MediaType.APPLICATION_JSON) public Response persisFlow(InputStream stream) { log.info("#### Pushing a flow"); ObjectNode jsonTree = null; List<String> devices = controller.getAvailableDevices(); try { jsonTree = (ObjectNode) mapper().readTree(stream); JsonNode devId = jsonTree.get("DeviceId"); JsonNode payload = jsonTree.get("Payload"); String sPayload = payload.toString(); log.info("Device Id" + devId.asText()); log.info("Payload Text value " + payload.textValue() + " toString " + payload.toString() + "Type " + payload.getNodeType().toString()); if (devId == null || devId.asText().isEmpty() || devices.contains(devId.asText()) == false) { throw new IllegalArgumentException(INVALID_DEVICEID); } if (payload == null || sPayload.isEmpty()) { throw new IllegalArgumentException(INVALID_FLOW); } DeviceId deviceId = DeviceId.deviceId(devId.asText()); Blob blob = new Blob(sPayload.getBytes()); store.InsertBlob(deviceId, blob); controller.writeToDevice(deviceId, blob); incrPostCount(); log.info("#### Total num of posts : " + getNumPostRecieved()); return Response.ok().build(); } catch (/*IO*/Exception e) { e.printStackTrace(); log.info("###### ERROR " + e.getMessage()); } return Response.noContent().build(); }
From source file:org.agatom.springatom.cmp.action.DefaultActionsModelReader.java
private ActionModelReferenceMap flattenActionModels(final ObjectNode object) throws Exception { Assert.notNull(object, "ActionModel can not be null"); final ActionModelReferenceMap map = new ActionModelReferenceMap(); map.node = object;//from ww w .j a va 2 s.c o m if (this.hasSubmodels(object)) { final ArrayNode submodels = (ArrayNode) object.get("submodels"); for (final JsonNode node : submodels) { map.submodel.put(node.textValue(), node); } } if (this.hasActions(object)) { final ArrayNode actions = (ArrayNode) object.get("actions"); for (final JsonNode action : actions) { map.actions.add(action); } } return map; }
From source file:org.level28.android.moca.json.HomeDeserializer.java
@Override public List<HomeSection> fromInputStream(InputStream in) throws JsonDeserializerException { JsonNode root;/* ww w. j av a 2 s .c o m*/ try { root = sJsonMapper.readTree(in); } catch (IOException e) { throw new JsonDeserializerException("Internal Jackson error", e); } if (!root.isArray()) { throw new JsonDeserializerException("Root node is not an array"); } ArrayList<HomeSection> result = Lists.newArrayList(); for (JsonNode node : root) { if (!node.isObject()) { throw new JsonDeserializerException("Array element is not an object"); } final JsonNode header = node.path("header"); final JsonNode contents = node.path("contents"); if (header.isMissingNode() || contents.isMissingNode() || !header.isTextual() || !contents.isTextual()) { throw new JsonDeserializerException("Malformed entry"); } result.add(new HomeSection(header.textValue(), contents.textValue())); } return result; }
From source file:de.dfki.kiara.jsonrpc.JsonRpcProtocol.java
public Object parseMessageName(JsonNode messageNode) throws IOException { JsonNode methodNode = messageNode.get("method"); Object method = null;//from www.j av a2s . co m if (methodNode != null) { if (!methodNode.isTextual() && !methodNode.isNull()) { throw new IOException("Invalid 'id' member"); } method = methodNode.textValue(); } return method; }
From source file:com.ning.metrics.serialization.hadoop.pig.SmileStorage.java
private Object getJsonValue(final SchemaFieldType type, final JsonNode node) { switch (type) { case BOOLEAN: return node.intValue(); case BYTE:// w ww. ja v a 2 s . c o m return new Byte(node.textValue()); case SHORT: case INTEGER: return node.intValue(); case LONG: case DATE: return node.longValue(); case DOUBLE: return node.doubleValue(); case IP: case STRING: default: return node.textValue(); } }