List of usage examples for com.fasterxml.jackson.databind JsonNode asText
public abstract String asText();
From source file:com.redhat.lightblue.crud.validator.EnumChecker.java
@Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, Path valuePath, JsonDoc doc, JsonNode fieldValue) { String name = ((EnumConstraint) constraint).getName(); Set<String> values = null; if (name != null) { // find value set for this enum Enum e = validator.getEntityMetadata().getEntityInfo().getEnums().getEnum(name); if (e != null) { values = e.getValues();//from w w w . j av a 2 s. c o m } } if (null == values || !values.contains(fieldValue.asText())) { validator.addDocError(Error.get(CrudConstants.ERR_INVALID_ENUM, fieldValue.asText())); } }
From source file:org.waarp.openr66.protocol.http.rest.handler.DbRuleR66RestMethodHandler.java
protected DbRule getItem(HttpRestHandler handler, RestArgument arguments, RestArgument result, Object body) throws HttpIncorrectRequestException, HttpInvalidAuthenticationException, HttpNotFoundRequestException { ObjectNode arg = arguments.getUriArgs().deepCopy(); arg.setAll(arguments.getBody());/*w w w .j a va2 s. c o m*/ try { JsonNode node = RestArgument.getId(arg); String id; if (node.isMissingNode()) { // shall not be but continue however id = arg.path(DbRule.Columns.IDRULE.name()).asText(); } else { id = node.asText(); } return new DbRule(handler.getDbSession(), id); } catch (WaarpDatabaseException e) { throw new HttpNotFoundRequestException("Issue while reading from database " + arg, e); } }
From source file:com.facebook.api.FacebookPostActivitySerializer.java
private void addIcon(Activity activity, JsonNode value) { Icon icon = new Icon(); //Apparently the Icon didn't map from the schema very well icon.setAdditionalProperty("url", value.asText()); activity.setIcon(icon);/*from w w w.j a va 2s .c om*/ }
From source file:org.waarp.openr66.protocol.http.rest.handler.DbHostAuthR66RestMethodHandler.java
protected DbHostAuth getItem(HttpRestHandler handler, RestArgument arguments, RestArgument result, Object body) throws HttpIncorrectRequestException, HttpInvalidAuthenticationException, HttpNotFoundRequestException { ObjectNode arg = arguments.getUriArgs().deepCopy(); arg.setAll(arguments.getBody());// www . j av a2s . co m try { JsonNode node = RestArgument.getId(arg); String id; if (node.isMissingNode()) { // shall not be but continue however id = arg.path(DbHostAuth.Columns.HOSTID.name()).asText(); } else { id = node.asText(); } return new DbHostAuth(handler.getDbSession(), id); } catch (WaarpDatabaseException e) { throw new HttpNotFoundRequestException("Issue while reading from database " + arg + " was " + arguments, e); } }
From source file:net.logstash.logback.pattern.AbstractJsonPatternParser.java
private NodeWriter<Event> parseValue(JsonNode node) { if (node.isTextual()) { ValueGetter<?, Event> getter = makeComputableValueGetter(node.asText()); return new ComputableValueWriter<Event>(getter); } else if (node.isArray()) { return parseArray(node); } else if (node.isObject()) { return parseObject(node); } else {//from w ww . j a va2 s.co m // Anything else, we will be just writing as is (nulls, numbers, booleans and whatnot) return new ConstantValueWriter<Event>(node); } }
From source file:org.dswarm.graph.resources.XMLResource.java
@POST @Path("/get") @Consumes(MediaType.APPLICATION_JSON)/*from w w w .j av a 2 s . co m*/ @Produces(MediaType.APPLICATION_XML) public Response readXML(final String jsonObjectString, @Context final GraphDatabaseService database) throws DMPGraphException { XMLResource.LOG.debug("try to read XML records from graph db"); final ObjectNode json; try { json = objectMapper.readValue(jsonObjectString, ObjectNode.class); } catch (final IOException e) { final String message = "could not deserialise request JSON for read from graph DB request"; XMLResource.LOG.debug(message); throw new DMPGraphException(message, e); } final String recordClassUri = json.get(DMPStatics.RECORD_CLASS_URI_IDENTIFIER).asText(); final String dataModelUri = json.get(DMPStatics.DATA_MODEL_URI_IDENTIFIER).asText(); final JsonNode rootAttributePathNode = json.get(DMPStatics.ROOT_ATTRIBUTE_PATH_IDENTIFIER); final Optional<AttributePath> optionalRootAttributePath = Optional .fromNullable(AttributePathUtil.parseAttributePathNode(rootAttributePathNode)); final Optional<String> optionalRecordTag; final JsonNode recordTagNode = json.get(DMPStatics.RECORD_TAG_IDENTIFIER); if (recordTagNode != null) { optionalRecordTag = Optional.fromNullable(recordTagNode.asText()); } else { optionalRecordTag = Optional.absent(); } final JsonNode versionNode = json.get(DMPStatics.VERSION_IDENTIFIER); final Optional<Integer> optionalVersion; if (versionNode != null) { optionalVersion = Optional.fromNullable(versionNode.asInt()); } else { optionalVersion = Optional.absent(); } final JsonNode allVersionsNode = json.get(DMPStatics.ALL_VERSIONS_IDENTIFIER); final Optional<Boolean> optionalAllversion; if (allVersionsNode != null) { optionalAllversion = Optional.fromNullable(allVersionsNode.asBoolean()); } else { optionalAllversion = Optional.absent(); } final Optional<JsonNode> optionalOriginalDataTypeNode = Optional .fromNullable(json.get(DMPStatics.ORIGINAL_DATA_TYPE_IDENTIFIER)); final Optional<String> optionalOriginalDataType; if (optionalOriginalDataTypeNode.isPresent()) { final Optional<String> optionalOriginalDataTypeFromJSON = Optional .fromNullable(optionalOriginalDataTypeNode.get().asText()); if (optionalOriginalDataTypeFromJSON.isPresent()) { optionalOriginalDataType = optionalOriginalDataTypeFromJSON; } else { optionalOriginalDataType = Optional.absent(); } } else { optionalOriginalDataType = Optional.absent(); } LOG.debug("try to read XML records for data model uri = '{}' and record class uri = '{}' from graph db", dataModelUri, recordClassUri); final TransactionHandler tx = new Neo4jTransactionHandler(database); final NamespaceIndex namespaceIndex = new NamespaceIndex(database, tx); final XMLReader xmlReader = new PropertyGraphXMLReader(optionalRootAttributePath, optionalRecordTag, recordClassUri, dataModelUri, optionalVersion, optionalAllversion, optionalOriginalDataType, database, tx, namespaceIndex); final StreamingOutput stream = new StreamingOutput() { @Override public void write(final OutputStream os) throws IOException, WebApplicationException { try { final BufferedOutputStream bos = new BufferedOutputStream(os, 1024); final Optional<XMLStreamWriter> optionalWriter = xmlReader.read(bos); if (optionalWriter.isPresent()) { optionalWriter.get().flush(); optionalWriter.get().close(); LOG.debug( "finished reading '{}' XML records for data model uri = '{}' and record class uri = '{}' from graph db", xmlReader.recordCount(), dataModelUri, recordClassUri); } else { bos.close(); os.close(); LOG.debug( "couldn't find any XML records for data model uri = '{}' and record class uri = '{}' from graph db", dataModelUri, recordClassUri); } } catch (final DMPGraphException | XMLStreamException e) { throw new WebApplicationException(e); } } }; return Response.ok(stream, MediaType.APPLICATION_XML_TYPE).build(); }
From source file:com.marklogic.entityservices.tests.TestInstanceConverterGenerator.java
private String moduleImport(String entityType) { InputStream is = this.getClass().getResourceAsStream("/json-models/" + entityType); ObjectMapper mapper = new ObjectMapper(); ObjectNode controlFile = null;//www .ja v a 2s. c om try { controlFile = (ObjectNode) mapper.readTree(is); } catch (IOException e) { throw new RuntimeException(e); } JsonNode baseUriNode = controlFile.get("info").get("baseUri"); String baseUri = null; if (baseUriNode == null) { baseUri = "http://example.org/"; } else { baseUri = baseUriNode.asText(); } String uriPrefix = baseUri; if (!baseUri.matches(".*[#/]$")) { uriPrefix += "#"; } String entityTypeName = entityType.replace(".json", ""); String moduleName = "/ext/" + entityTypeName + ".xqy"; return "import module namespace conv = \"" + uriPrefix + entityTypeName + "\" at \"" + moduleName + "\"; "; }
From source file:org.jmingo.mapping.convert.mongo.type.deserialize.MongoDateDeserializer.java
/** * {@inheritDoc}/*from ww w . j a v a2 s . c o m*/ */ @Override public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode tree = jp.readValueAsTree(); if (tree.isPojo()) { POJONode pojoNode = (POJONode) tree; Object pojo = pojoNode.getPojo(); if (pojo instanceof Date) { return (Date) pojoNode.getPojo(); } else { throw new RuntimeException("unsupported date type, expected: " + Date.class.getName()); } } String stringDate = tree.asText(); StdDateFormat stdDateFormat = new StdDateFormat(); try { return stdDateFormat.parse(stringDate); } catch (ParseException e) { throw Throwables.propagate(e); } }
From source file:org.waarp.openr66.protocol.http.rest.handler.DbConfigurationR66RestMethodHandler.java
protected DbConfiguration getItem(HttpRestHandler handler, RestArgument arguments, RestArgument result, Object body)//from ww w . ja v a 2s .c om throws HttpIncorrectRequestException, HttpInvalidAuthenticationException, HttpNotFoundRequestException { ObjectNode arg = arguments.getUriArgs().deepCopy(); arg.setAll(arguments.getBody()); try { JsonNode node = RestArgument.getId(arg); String id; if (node.isMissingNode()) { // shall not be but continue however id = arg.path(DbConfiguration.Columns.HOSTID.name()).asText(); } else { id = node.asText(); } return new DbConfiguration(handler.getDbSession(), id); } catch (WaarpDatabaseException e) { throw new HttpNotFoundRequestException("Issue while reading from database " + arg, e); } }
From source file:com.ikanow.aleph2.security.utils.LdifExportUtil.java
public Tuple2<Set<String>, Set<String>> getRolesAndPermissions(String principalName) { Set<String> roleNames = new HashSet<String>(); Set<String> permissions = new HashSet<String>(); Optional<JsonNode> result; try {// w w w . j ava 2s. c om ObjectId objecId = new ObjectId(principalName); result = getPersonStore().getObjectBySpec(CrudUtils.anyOf().when("_id", objecId)).get(); if (result.isPresent()) { // community based roles JsonNode person = result.get(); JsonNode communities = person.get("communities"); if (communities != null && communities.isArray()) { if (communities.size() > 0) { roleNames.add(principalName + "_user_group"); } for (final JsonNode community : communities) { JsonNode type = community.get("type"); if (type != null && "user".equalsIgnoreCase(type.asText())) { String communityId = community.get("_id").asText(); String communityName = community.get("name").asText(); permissions.add(communityId); logger.debug("Permission (ShareIds) loaded for " + principalName + ",(" + communityName + "):" + communityId); } } } // communities } } catch (Exception e) { logger.error("Caught Exception", e); } logger.debug("Roles loaded for " + principalName + ":"); logger.debug(roleNames); return Tuples._2T(roleNames, permissions); }