Java Code Examples for com.fasterxml.jackson.databind.JsonNode#withArray()
The following examples show how to use
com.fasterxml.jackson.databind.JsonNode#withArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AvroToProtoSchema.java From metastore with Apache License 2.0 | 6 votes |
private DescriptorProtos.DescriptorProto.Builder protoMessageOf(JsonNode complexNode) { String messageName = extractName(complexNode); String packageName = extractPackageName(complexNode); DescriptorProtos.DescriptorProto.Builder descriptor = DescriptorProtos.DescriptorProto.newBuilder().setName(messageName); JsonNode fields = complexNode.withArray("fields"); int i = 1; for (JsonNode field : fields) { String fieldName = field.path("name").asText(); DescriptorProtos.FieldDescriptorProto.Builder fieldDescriptor = DescriptorProtos.FieldDescriptorProto.newBuilder() .setName(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, fieldName)) .setNumber(i); fieldDescriptor = protoFieldOf(descriptor, fieldDescriptor, packageName, field); descriptor.addField(fieldDescriptor); i++; } messageMap.put(fullName(packageName, messageName), descriptor.build()); return descriptor; }
Example 2
Source File: LayersViewStateIoProvider.java From constellation with Apache License 2.0 | 6 votes |
@Override public void readObject(final int attributeId, final int elementId, final JsonNode jnode, final GraphWriteMethods graph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, final ImmutableObjectCache cache) throws IOException { if (!jnode.isNull()) { final List<LayerDescription> layerDescriptions = new ArrayList<>(); final ArrayNode layersArray = (ArrayNode) jnode.withArray("layers"); for (int i = 0; i < layersArray.size(); i++) { if (layersArray.get(i).isNull()) { layerDescriptions.add(null); } else { // create LayerDescription with index, visibility, query and description layerDescriptions.add(new LayerDescription( layersArray.get(i).get(0).asInt(), layersArray.get(i).get(1).asBoolean(), layersArray.get(i).get(2).asText(), layersArray.get(i).get(3).asText() )); } } final LayersViewState state = new LayersViewState(layerDescriptions); graph.setObjectValue(attributeId, elementId, state); } }
Example 3
Source File: Rules.java From remote-monitoring-services-java with MIT License | 6 votes |
private ArrayList<JsonNode> getResultListFromJson(JsonNode response) { ArrayList<JsonNode> resultList = new ArrayList<>(); // ignore case when parsing items array String itemsKey = response.has("Items") ? "Items" : "items"; for (JsonNode item : response.withArray(itemsKey)) { try { resultList.add(item); } catch (Exception e) { log.error("Could not parse data from Key Value Storage"); throw new CompletionException( new ExternalDependencyException( "Could not parse data from Key Value Storage")); } } return resultList; }
Example 4
Source File: CameraIOProviderV0.java From constellation with Apache License 2.0 | 5 votes |
/** * Helper method to get a Vector3f from a JsonNode. * * @param node The JsonNode to get the Vector3f from. * @param label The label of the Vector3f node. * * @return */ private static Vector3f getVector(final JsonNode node, final String label) { if (node.hasNonNull(label)) { final ArrayNode array = (ArrayNode) node.withArray(label); return new Vector3f((float) array.get(0).asDouble(), (float) array.get(1).asDouble(), (float) array.get(2).asDouble()); } return null; }
Example 5
Source File: CameraIOProvider.java From constellation with Apache License 2.0 | 5 votes |
/** * Helper method to get a Vector3f from a JsonNode. * * @param node The JsonNode to get the Vector3f from. * @param label The label of the Vector3f node. * * @return */ private static Vector3f getVector(final JsonNode node, final String label) { if (node.hasNonNull(label)) { final ArrayNode array = (ArrayNode) node.withArray(label); return new Vector3f((float) array.get(0).asDouble(), (float) array.get(1).asDouble(), (float) array.get(2).asDouble()); } return null; }
Example 6
Source File: TableStateIOProvider.java From constellation with Apache License 2.0 | 5 votes |
@Override public void readObject(final int attributeId, final int elementId, final JsonNode jnode, final GraphWriteMethods graph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, ImmutableObjectCache cache) throws IOException { if (!jnode.isNull()) { final int posx = jnode.get("posx").asInt(0); final int posy = jnode.get("posy").asInt(0); final boolean selectedOnly = jnode.hasNonNull(SELECTED_ONLY) && jnode.get(SELECTED_ONLY).asBoolean(false); final TableState state = new TableState(new Point(posx, posy), selectedOnly); final ArrayNode columns = (ArrayNode) jnode.withArray("columns"); for (final JsonNode column : columns) { // Null labels means dummy value. final String label = column.get(LABEL).isNull() ? null : column.get(LABEL).asText(); // If width is missing, use a marker <0 // to indicate deafult width. final int width = column.get("width").asInt(-1); final String segmentText = column.get("segment").asText(); try { final Segment segment = Segment.valueOf(segmentText); final ColumnState cs = new ColumnState(label, segment, width); state.columns.add(cs); } catch (IllegalArgumentException ex) { LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex); } } final ArrayNode sortOrder = (ArrayNode) jnode.withArray("sortOrder"); for (final JsonNode so : sortOrder) { final String s = so.asText(); state.sortOrder.add(s); } graph.setObjectValue(attributeId, 0, state); } }
Example 7
Source File: PerspectiveIOProvider.java From constellation with Apache License 2.0 | 5 votes |
/** * Read a Vector3f from a JsonNode. * * @param node The JsonNode to get the Vector3f from. * @param label The label of the Vector3f node. * * @return */ private static Vector3f readVector(final JsonNode node, final String label) { if (node.hasNonNull(label)) { final ArrayNode array = (ArrayNode) node.withArray(label); return new Vector3f((float) array.get(0).asDouble(), (float) array.get(1).asDouble(), (float) array.get(2).asDouble()); } return null; }
Example 8
Source File: Jsons2Xsd.java From jsons2xsd with MIT License | 5 votes |
private static List<String> getRequiredList(JsonNode jsonNode) { if (jsonNode.path(FIELD_REQUIRED).isMissingNode()) { return Collections.emptyList(); } Assert.isTrue(jsonNode.path(FIELD_REQUIRED).isArray(), "'required' property must have type: array"); List<String> requiredList = new ArrayList<>(); for (JsonNode requiredField : jsonNode.withArray(FIELD_REQUIRED)) { Assert.isTrue(requiredField.isTextual(), "required must be string"); requiredList.add(requiredField.asText()); } return requiredList; }
Example 9
Source File: AnalyticViewStateIoProvider.java From constellation with Apache License 2.0 | 4 votes |
@Override public void readObject(final int attributeId, final int elementId, final JsonNode jnode, final GraphWriteMethods graph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, final ImmutableObjectCache cache) throws IOException { if (!jnode.isNull()) { final int currentIndex = jnode.get("index").asInt(); final List<AnalyticQuestionDescription<?>> questions = new ArrayList<>(); final ArrayNode questionArray = (ArrayNode) jnode.withArray("questions"); for (int i = 0; i < questionArray.size(); i++) { if (questionArray.get(i).isNull()) { questions.add(null); } else { questions.add(AnalyticUtilities.lookupAnalyticQuestionDescription(questionArray.get(i).asText())); } } final List<List<SelectableAnalyticPlugin>> plugins = new ArrayList<>(); final Iterator<JsonNode> pluginListIterator = jnode.get("pluginLists").iterator(); while (pluginListIterator.hasNext()) { final JsonNode pluginList = pluginListIterator.next(); final List<SelectableAnalyticPlugin> selectablePluginList = new ArrayList<>(); final Iterator<JsonNode> pluginIterator = pluginList.get("pluginList").iterator(); while (pluginIterator.hasNext()) { final JsonNode pluginEntry = pluginIterator.next(); final SelectableAnalyticPlugin selectablePlugin = AnalyticConfigurationPane.lookupSelectablePlugin(pluginEntry.get("name").asText()); if (selectablePlugin != null) { final Iterator<Map.Entry<String, JsonNode>> parametersIterator = pluginEntry.get("parameters").fields(); while (parametersIterator.hasNext()) { final Map.Entry<String, JsonNode> parametersEntry = parametersIterator.next(); final String parameterName = parametersEntry.getKey(); final String parameterValue = parametersEntry.getValue().asText(); selectablePlugin.setUpdatedParameter(parameterName, parameterValue); } selectablePluginList.add(selectablePlugin); } } plugins.add(selectablePluginList); } final AnalyticViewState state = new AnalyticViewState(currentIndex, questions, plugins); graph.setObjectValue(attributeId, elementId, state); } }