Refine search
String fqn = null; ObjectNode object = new ObjectMapper().readValue(body, ObjectNode.class); if (!object.has(TYPE) || !object.get(TYPE).isTextual() || !object.get(TYPE).getTextValue().equals("record")) { throw new IllegalArgumentException("The data provided is not a record!"); if (!object.has(NAMESPACE) || !object.get(NAMESPACE).isTextual()) { throw new IllegalArgumentException("No namespace specified!"); } else if (!object.has(NAME) || !object.get(NAME).isTextual()) { throw new IllegalArgumentException("No name specified!"); } else { fqn = object.get(NAMESPACE).getTextValue() + "." + object.get(NAME).getTextValue(); if (!object.has(VERSION) || !object.get(VERSION).isInt()) { object.put(VERSION, 1); schema.setVersion(object.get(VERSION).asInt()); if (!object.has(DEPENDENCIES)) { schema.setDependencySet(dependencies); } else if (!object.get(DEPENDENCIES).isArray()) { throw new IllegalArgumentException("Illegal dependencies format!"); } else { for (JsonNode child : object.get(DEPENDENCIES)) { if (!child.isObject() || !child.has(FQN) || !child.get(FQN).isTextual() || !child.has(VERSION) || !child.get(VERSION).isInt()) {
public Object(JsonNode n, NodeCursor p) { super(JsonStreamContext.TYPE_OBJECT, p); _contents = ((ObjectNode) n).getFields(); _needEntry = true; }
ArrayNode dataTab = JsonNodeFactory.instance.arrayNode(); for ( int i = iDisplayStart; i < (iDisplayStart + iDisplayLength); ++i ) ObjectNode data = JsonNodeFactory.instance.objectNode(); int docId = cachedSearch.getNthDocId(i); SearchItem item = logSearch.toResult(docId); data.put("DT_RowId", "index-query-result-" + docId); data.put("0", getTypeName(EntryTypes.getFromId(item.getType()))); data.put("1", dateFormatter.format(item.getDate())); data.put("2", trimPath(item.getPath())); dataTab.add(data); node = JsonNodeFactory.instance.objectNode(); node.put("sEcho", sEcho); node.put("iTotalRecords", logSearch.getDocQty()); node.put("iTotalDisplayRecords", cachedSearch.getTotalHits()); node.put("aaData", dataTab); return node.toString();
@Override public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (o.getClass() != getClass()) { return false; } ObjectNode other = (ObjectNode) o; if (other.size() != size()) { return false; } if (_children != null) { for (Map.Entry<String, JsonNode> en : _children.entrySet()) { String key = en.getKey(); JsonNode value = en.getValue(); JsonNode otherValue = other.get(key); if (otherValue == null || !otherValue.equals(value)) { return false; } } } return true; }
public String getNodeData(@QueryParam("key") String key) throws Exception ObjectNode node = JsonNodeFactory.instance.objectNode(); try node.put("bytes", bytesToString(bytes)); node.put("str", new String(bytes, "UTF-8")); } else { node.put("bytes", ""); node.put("str", ""); node.put("stat", reflectToString(stat)); node.put("bytes", ""); node.put("str", ""); node.put("stat", "* not found * "); node.put("bytes", ""); node.put("str", "Exception"); node.put("stat", e.getMessage()); return node.toString();
objectNode.put("type", schemaType); if (objectProperties != null) { try { objectNode.put("properties", new ObjectMapper().readValue(objectProperties, JsonNode.class)); } catch (IOException e) { throw new IllegalStateException(e); objectNode.put("items", new ObjectMapper().readValue(itemDefinition, JsonNode.class)); } catch (IOException e) { throw new IllegalStateException(e);
private List<FileData> recursiveShallowExport(List<FileData> files, CTLSchemaDto parent) throws Exception { files.add(this.shallowExport(parent)); ObjectNode object = new ObjectMapper().readValue(parent.getBody(), ObjectNode.class); ArrayNode dependencies = (ArrayNode) object.get(DEPENDENCIES); if (dependencies != null) { for (JsonNode node : dependencies) { ObjectNode dependency = (ObjectNode) node; String fqn = dependency.get(FQN).getTextValue(); Integer version = dependency.get(VERSION).getIntValue(); CTLSchemaDto child = this.findAnyCtlSchemaByFqnAndVerAndTenantIdAndApplicationId( fqn, version, parent.getMetaInfo().getTenantId(), parent.getMetaInfo().getApplicationId()); Validate.notNull(child, MessageFormat.format("The dependency [{0}] was not found!", fqn)); this.recursiveShallowExport(files, child); } } return files; } }
public JsonConfig(String json) throws Exception { ObjectMapper mapper = new ObjectMapper(); JsonNode nodex = mapper.readValue(json, JsonNode.class); if (nodex instanceof ObjectNode) node = (ObjectNode) nodex; else { node = ((ArrayNode)nodex).objectNode(); node.put("default", nodex); } }
public static Map<String, Object> parseAsJSONValue(String src) { ObjectMapper mapper = new ObjectMapper(); ObjectNode rootNode; try { rootNode = (ObjectNode) mapper.readValue(src, JsonNode.class); } catch (JsonParseException e) { throw new RuntimeException(e); } catch (JsonMappingException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } HashMap<String, Object> map = new HashMap<String, Object>(); for (Iterator<Entry<String, JsonNode>> iter = rootNode.getFields(); iter .hasNext();) { Entry<String, JsonNode> field = iter.next(); JsonNode value = field.getValue(); Object o = jsonNodeAsSimpleObject(value); map.put(field.getKey(), o); } return map; }
ObjectMapper mapper = new ObjectMapper(); ObjectNode node = JsonNodeFactory.instance.objectNode(); if ( responseIsJson ) node.put("response", mapper.readTree(mapper.getJsonFactory().createJsonParser(remoteResponse))); node.put("response", remoteResponse); node.put("errorMessage", errorMessage); node.put("success", errorMessage.length() == 0);
@Override public void writeTo(ServiceNames serviceNames, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { ObjectMapper mapper = new ObjectMapper(); ArrayNode arrayNode = mapper.createArrayNode(); for ( String name : serviceNames.getNames() ) { ObjectNode node = mapper.createObjectNode(); node.put("name", name); arrayNode.add(node); } mapper.writer().writeValue(entityStream, arrayNode); }
@BeforeEach public void setUpMockRequest() { ObjectMapper mapper = new ObjectMapper(); ObjectNode mockPluginDef = mapper.createObjectNode(); mockPluginDef.put("foo", "bar"); //$NON-NLS-1$ //$NON-NLS-2$ mockPluginDefinitionsArray = mapper.createArrayNode(); mockPluginDefinitionsArray.add(mockPluginDef); when(mockApplicationModeObject.toString()).thenReturn(APPLICATION_MODE); when(mockRequest.getAttribute(WebAdminHostPageServlet.ATTR_APPLICATION_MODE)).thenReturn(mockApplicationModeObject); when(mockRequest.getAttribute(WebAdminHostPageServlet.ATTR_PLUGIN_DEFS)).thenReturn(mockPluginDefinitionsArray); }
/** * Change encoding of uuids from <b>latin1 (ISO-8859-1)</b> to <b>base64</b>. * * @param json the json that should be processed * @return the json with changed uuids * @throws IOException the io exception */ public static JsonNode encodeUuids(JsonNode json) throws IOException { if (json.has(UUID_FIELD)) { JsonNode jsonNode = json.get(UUID_FIELD); if (jsonNode.has(UUID_VALUE)) { String value = jsonNode.get(UUID_VALUE).asText(); String encodedValue = Base64.getEncoder().encodeToString(value.getBytes("ISO-8859-1")); ((ObjectNode) jsonNode).put(UUID_VALUE, encodedValue); } } for (JsonNode node : json) { if (node.isContainerNode()) { encodeUuids(node); } } return json; }
/** * Given a {@link ContainerModel} JSON with an unknown field, deserialization should properly ignore it. */ @Test public void testDeserializeUnknownTaskModelField() throws IOException { ObjectNode jobModelJson = buildJobModelJson(); ObjectNode taskModelJson = (ObjectNode) jobModelJson.get("containers").get("1").get("tasks").get("test"); taskModelJson.put("unknown_task_model_key", "unknown_task_model_value"); assertEquals(this.jobModel, deserializeFromObjectNode(jobModelJson)); }
private void addTo( ObjectNode resourceNode, String uriPrefix, AbstractResourceMethod srm, String path ){ if(resourceNode.get( uriPrefix ) == null){ ObjectNode inner = JsonNodeFactory.instance.objectNode(); inner.put("path", path); inner.put("methods", JsonNodeFactory.instance.arrayNode()); resourceNode.put( uriPrefix, inner ); } ((ArrayNode) resourceNode.get( uriPrefix ).get("methods")).add( srm.getHttpMethod() ); }
@Override public ObjectNode serialize(ObjectMapper mapper, CorefFeature coref) { ObjectNode jCoref = mapper.createObjectNode(); jCoref.put(IS_REPRESENTATIVE_TAG, coref.isRepresentative()); Set<Span> mentions = coref.getMentions(); ArrayNode jMentions = mapper.createArrayNode(); for(Span mention : mentions) { ObjectNode jMention = mapper.createObjectNode(); jMention.put(MENTION_TYPE_TAG, mention.getType().toString()); jMention.put(MENTION_START_TAG, mention.getStart()); jMention.put(MENTION_END_TAG, mention.getEnd()); jMentions.add(jMention); } jCoref.put(MENTIONS_TAG, jMentions); return jCoref; }
@GET @Path("{instanceName}/healthreports") public Response getHealthReportsOnInstance(@PathParam("clusterId") String clusterId, @PathParam("instanceName") String instanceName) throws IOException { HelixDataAccessor accessor = getDataAccssor(clusterId); ObjectNode root = JsonNodeFactory.instance.objectNode(); root.put(Properties.id.name(), instanceName); ArrayNode healthReportsNode = root.putArray(InstanceProperties.healthreports.name()); List<String> healthReports = accessor.getChildNames(accessor.keyBuilder().healthReports(instanceName)); if (healthReports != null && healthReports.size() > 0) { healthReportsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(healthReports)); } return JSONRepresentation(root); }
private static JsonNode injectUuidsFromJsonNodes(JsonNode json, Schema schema) { if (json == null) { return json; } switch (schema.getType()) { case RECORD: schema.getFields().stream() .filter(f -> !f.name().equals(UUID_FIELD)) .forEach(f -> injectUuidsFromJsonNodes(json.get(f.name()), f.schema())); boolean addressable = schema.getFields().stream().filter(f -> f.name().equals( UUID_FIELD)).findFirst().isPresent(); if (addressable) { ((ObjectNode) json).put(UUID_FIELD, (Integer) null); } break; case UNION: schema.getTypes() .forEach(s -> injectUuidsFromJsonNodes(json.get(s.getName()), s)); break; case ARRAY: json.getElements().forEachRemaining((elem) -> injectUuids(elem, schema.getElementType())); break; default: return json; } return json; }
@Override public List<IConfig> getNodes() { LinkedList<IConfig> out = new LinkedList<>(); for ( Map.Entry<String, JsonNode> entry : MCollection.iterate(node.getFields()) ) { JsonNode child = entry.getValue(); String childName = entry.getKey(); if (child !=null && child.isArray()) { for (int i = 0; i < child.size(); i++) out.add( new JsonConfig(childName, this, child.get(i))); } else if (child !=null && child.isObject()) out.add( new JsonConfig(childName, this, child)); } return out; }
@Test public void testQueryExplanation_typeCast2() { String query = "ResourceGroup.<ResourceGroup>children{*}"; QueryContext qc = newQueryContext(CMSDB_REPO, IBranch.DEFAULT_BRANCH); qc.setAllowFullTableScan(true); qc.setExplain(true); IQueryResult queryResult = queryService.query(query, qc); Assert.assertNotNull(queryResult.getExplanations()); List<IQueryExplanation> explans = queryResult.getExplanations(); Assert.assertEquals(3, explans.size()); // first two is search explanation, the last one is the join explanation ObjectNode objectNode = (ObjectNode) explans.get(0).getJsonExplanation(); String queryType0 = objectNode.get("criteria").get("$and").get(0).get("_t").getTextValue(); Assert.assertTrue(queryType0.equals("ResourceGroup")); Assert.assertTrue(objectNode.has("usedTime")); Assert.assertTrue(objectNode.has("limit")); Assert.assertTrue(objectNode.has("sort")); objectNode = (ObjectNode) explans.get(1).getJsonExplanation(); String queryType1 = objectNode.get("criteria").get("$and").get(0).get("_t").getTextValue(); Assert.assertTrue(queryType1.equals("ResourceGroup")); }