List of usage examples for com.fasterxml.jackson.databind.node ArrayNode get
public JsonNode get(String paramString)
From source file:com.siemens.sw360.datahandler.common.JacksonUtils.java
public static int arrayPosition(ArrayNode array, String needle) { for (int i = 0; i < array.size(); i++) { JsonNode jsonNode = array.get(i); if (jsonNode.isTextual() && needle.equals(jsonNode.textValue())) { return i; }/*w w w . ja v a 2 s. c o m*/ } return -1; }
From source file:org.teavm.flavour.json.test.TeaVMJSONRunner.java
public static final JsonNode convert(JsonNodeFactory nf, Node node) { if (node.isNull()) { return nf.nullNode(); } else if (node.isBoolean()) { BooleanNode booleanNode = (BooleanNode) node; return nf.booleanNode(booleanNode.getValue()); } else if (node.isNumber()) { NumberNode numberNode = (NumberNode) node; if (numberNode.isInt()) { return nf.numberNode(numberNode.getIntValue()); } else {//from ww w. java2 s. c o m return nf.numberNode(numberNode.getValue()); } } else if (node.isString()) { StringNode stringNode = (StringNode) node; return nf.textNode(stringNode.getValue()); } else if (node.isArray()) { ArrayNode result = nf.arrayNode(); org.teavm.flavour.json.tree.ArrayNode source = (org.teavm.flavour.json.tree.ArrayNode) node; for (int i = 0; i < source.size(); ++i) { result.add(convert(nf, source.get(i))); } return result; } else if (node.isObject()) { com.fasterxml.jackson.databind.node.ObjectNode result = nf.objectNode(); ObjectNode objectNode = (ObjectNode) node; for (String key : objectNode.allKeys()) { result.replace(key, convert(nf, objectNode.get(key))); } return result; } else { throw new IllegalArgumentException("Can't convert this JSON node"); } }
From source file:org.gitana.platform.client.util.DriverUtil.java
public static List<String> toStringList(Response response) { List<String> list = new ArrayList<String>(); ObjectNode objectNode = response.getObjectNode(); ArrayNode rows = (ArrayNode) objectNode.get("rows"); for (int i = 0; i < rows.size(); i++) { list.add(rows.get(i).textValue()); }/*w w w. jav a 2s .c o m*/ return list; }
From source file:com.palominolabs.testutil.JsonAssert.java
public static void assertJsonArrayEquals(String msg, ArrayNode expected, ArrayNode actual) { assertEquals(msg + "/array length", expected.size(), actual.size()); for (int i = 0; i < expected.size(); i++) { assertJsonNodeEquals(msg + "/index <" + i + ">", expected.get(i), actual.get(i)); }// w w w .j ava 2 s . c o m }
From source file:org.gitana.platform.client.util.DriverUtil.java
public static ACL toACL(Response response) { ACL acl = new ACL(); ObjectNode objectNode = response.getObjectNode(); ArrayNode rows = (ArrayNode) objectNode.get("rows"); for (int x = 0; x < rows.size(); x++) { ObjectNode binding = (ObjectNode) rows.get(x); String principalId = binding.get(DomainPrincipal.FIELD_ID).textValue(); String principalType = binding.get(DomainPrincipal.FIELD_TYPE).textValue(); List<String> roles = new ArrayList<String>(); ArrayNode array = (ArrayNode) binding.get("authorities"); for (int i = 0; i < array.size(); i++) { roles.add(array.get(i).textValue()); }//w w w .ja v a 2 s . co m ACLEntry entry = new ACLEntry(); entry.setPrincipal(principalId); entry.setAuthorities(roles); acl.add(principalId, entry); } return acl; }
From source file:ru.histone.deparser.Deparser.java
public static int getNodeType(ArrayNode astArray) { return abs(astArray.get(0).asInt()); }
From source file:ru.histone.deparser.Deparser.java
protected static ArrayNode removeHistoneAstSignature(ArrayNode ast) { if (ast.size() == 2 && ast.get(0).isArray() && ast.get(1).isArray() && "HISTONE".equals(ast.get(0).get(0).asText())) { return (ArrayNode) ast.get(1); } else {//from w w w . j a va 2s. c o m return ast; } }
From source file:com.mirth.connect.client.ui.components.rsta.RSTAPreferences.java
static RSTAPreferences fromJSON(String keyStrokesJSON, String findReplaceJSON, String toggleOptionsJSON, String autoCompleteJSON) { ObjectMapper mapper = new ObjectMapper(); Map<String, KeyStroke> keyStrokeMap = new HashMap<String, KeyStroke>(); if (StringUtils.isNotBlank(keyStrokesJSON)) { try {//from ww w.ja v a2 s . com ObjectNode keyStrokesNode = (ObjectNode) mapper.readTree(keyStrokesJSON); for (Iterator<Entry<String, JsonNode>> it = keyStrokesNode.fields(); it.hasNext();) { Entry<String, JsonNode> entry = it.next(); KeyStroke keyStroke = null; if (!entry.getValue().isNull()) { ArrayNode arrayNode = (ArrayNode) entry.getValue(); if (arrayNode.size() > 1) { keyStroke = KeyStroke.getKeyStroke(arrayNode.get(0).asInt(), arrayNode.get(1).asInt()); } } keyStrokeMap.put(entry.getKey(), keyStroke); } } catch (Exception e) { e.printStackTrace(); } } FindReplaceProperties findReplaceProperties = FindReplaceProperties.fromJSON(findReplaceJSON); Map<String, Boolean> toggleOptions = new HashMap<String, Boolean>(); if (StringUtils.isNotBlank(toggleOptionsJSON)) { try { ObjectNode toggleOptionsNode = (ObjectNode) mapper.readTree(toggleOptionsJSON); for (Iterator<Entry<String, JsonNode>> it = toggleOptionsNode.fields(); it.hasNext();) { Entry<String, JsonNode> entry = it.next(); if (!entry.getValue().isNull()) { toggleOptions.put(entry.getKey(), entry.getValue().asBoolean()); } } } catch (Exception e) { e.printStackTrace(); } } AutoCompleteProperties autoCompleteProperties = AutoCompleteProperties.fromJSON(autoCompleteJSON); return new RSTAPreferences(keyStrokeMap, findReplaceProperties, toggleOptions, autoCompleteProperties); }
From source file:com.pros.jsontransform.plugin.sort.ArraySortByAvgAge.java
public static void sort(final ArrayNode arrayNode, final JsonNode sortNode, final ObjectTransformer transformer) throws ObjectTransformerException { // target array does not contain age information so // we need to use the source array from transformer context to perform the sort ArrayNode sourceArray = (ArrayNode) transformer.getSourceNode(); // move source and target array nodes to sorting array int size = arrayNode.size(); ArrayList<JsonNode> sortingArray = new ArrayList<JsonNode>(arrayNode.size()); for (int i = 0; i < size; i++) { ObjectNode sortingElement = transformer.mapper.createObjectNode(); sortingElement.put("source", sourceArray.get(i)); sortingElement.put("target", arrayNode.remove(0)); sortingArray.add(sortingElement); }//from w ww .ja v a 2 s .c o m // sort array sortingArray.sort(new AvgAgeComparator(sortNode)); // move nodes back to targetArray for (int i = 0; i < sortingArray.size(); i++) { arrayNode.add(sortingArray.get(i).get("target")); } }
From source file:com.helger.wsdlgen.exchange.InterfaceReader.java
@Nullable public static WGInterface readInterface(@Nonnull final IReadableResource aRes) { final ObjectNode aInterfaceNode = _readAsJSON(aRes); if (aInterfaceNode == null) return null; final String sInterfaceName = _getChildAsText(aInterfaceNode, "$name"); final String sInterfaceNamespace = _getChildAsText(aInterfaceNode, "$namespace"); final String sInterfaceEndpoint = _getChildAsText(aInterfaceNode, "$endpoint"); final WGInterface aInterface = new WGInterface(sInterfaceName, sInterfaceNamespace, sInterfaceEndpoint); // Dont't format global interface comment aInterface.setDocumentation(_getChildAsText(aInterfaceNode, "$doc")); // Add all types final ObjectNode aTypesNode = (ObjectNode) aInterfaceNode.get("$types"); if (aTypesNode != null) { // Read all contained types for (final Map.Entry<String, JsonNode> aTypeEntry : _getAllChildren(aTypesNode).entrySet()) { final String sTypeName = aTypeEntry.getKey(); final JsonNode aTypeNode = aTypeEntry.getValue(); if (!sTypeName.startsWith("$")) { final boolean bIsSimpleType = sTypeName.startsWith("#"); if (bIsSimpleType) { // Simple type final WGSimpleType aSimpleType = new WGSimpleType(sInterfaceNamespace, sTypeName.substring(1)); final WGTypeDef aSimpleTypeDef = new WGTypeDef(aSimpleType); for (final Map.Entry<String, JsonNode> aChildTypeEntry : _getAllChildren(aTypeNode) .entrySet()) { final String sTypeChildName = aChildTypeEntry.getKey(); final JsonNode aTypeChildNode = aChildTypeEntry.getValue(); if (sTypeChildName.equals("$doc")) aSimpleTypeDef.setDocumentation(_getDocumentation(aTypeChildNode.asText())); else if (sTypeChildName.equals("$extension")) { final String sExtension = aTypeChildNode.asText(); final IWGType aExtensionType = aInterface.getTypeOfName(sExtension); if (aExtensionType == null) throw new IllegalArgumentException("Simple type '" + aSimpleType.getName() + "' has invalid extension type '" + sExtension + "'"); aSimpleType.setExtension(aExtensionType); } else if (sTypeChildName.equals("$restriction")) { final String sRestriction = aTypeChildNode.asText(); final IWGType aRestrictionType = aInterface.getTypeOfName(sRestriction); if (aRestrictionType == null) throw new IllegalArgumentException("Simple type '" + aSimpleType.getName() + "' has invalid restriction type '" + sRestriction + "'"); aSimpleType.setRestriction(aRestrictionType); } else if (sTypeChildName.equals("$enum")) { final ArrayNode aEntries = (ArrayNode) aTypeChildNode; if (aEntries == null) throw new IllegalArgumentException( "Simple type '" + aSimpleType.getName() + "' has invalid enum entries"); // Convert all to string final List<WGEnumEntry> aEnumEntries = new ArrayList<WGEnumEntry>(); for (final JsonNode aPropValue : aEntries) { if (aPropValue instanceof ArrayNode) { // [key, documentation] final ArrayNode aProvValueList = (ArrayNode) aPropValue; aEnumEntries.add(new WGEnumEntry(aProvValueList.get(0).asText(), aProvValueList.get(1).asText())); } else { // Just the key, without documentation aEnumEntries.add(new WGEnumEntry(aPropValue.asText())); }/*from w ww . j a v a 2 s. co m*/ } aSimpleType.setEnumEntries(aEnumEntries); } else if (sTypeChildName.equals("$maxlength")) { final int nMaxLength = aTypeChildNode.asInt(-1); if (nMaxLength <= 0) throw new IllegalArgumentException("Simple type '" + aSimpleType.getName() + "' has invalid maxLength definition '" + aTypeChildNode.asText() + "'"); aSimpleType.setMaxLength(nMaxLength); } else if (!sTypeChildName.startsWith("$")) { // Only attributes allowed! if (!sTypeChildName.startsWith("@")) throw new IllegalArgumentException("Simple type '" + aSimpleType.getName() + "' may only have attributes and not '" + sTypeChildName + "'"); final WGTypeDef aTypeDef = _readTypeDef(aInterface, sTypeChildName, aTypeChildNode); aSimpleType.addChildAttribute(sTypeChildName.substring(1), aTypeDef); } else throw new IllegalStateException("Unhandled simple type child: " + sTypeChildName); } aInterface.addType(aSimpleTypeDef); } else { // Complex type final WGComplexType aComplexType = new WGComplexType(sInterfaceNamespace, sTypeName); final WGTypeDef aComplexTypeDef = new WGTypeDef(aComplexType); for (final Map.Entry<String, JsonNode> aChildTypeEntry : _getAllChildren(aTypeNode) .entrySet()) { final String sTypeChildName = aChildTypeEntry.getKey(); final JsonNode aTypeChildNode = aChildTypeEntry.getValue(); if (sTypeChildName.equals("$doc")) aComplexTypeDef.setDocumentation(_getDocumentation(aTypeChildNode.asText())); else if (sTypeChildName.equals("$type")) aComplexType.setType(EComplexType.getFromTagNameOrThrow(aTypeChildNode.asText())); else if (!sTypeChildName.startsWith("$")) { final WGTypeDef aChildTypeDef = _readTypeDef(aInterface, sTypeChildName, aTypeChildNode); // Attribute or element? if (sTypeChildName.startsWith("@")) aComplexType.addChildAttribute(sTypeChildName.substring(1), aChildTypeDef); else aComplexType.addChildElement(sTypeChildName, aChildTypeDef); } else throw new IllegalStateException("Unhandled complex type child: " + sTypeChildName); } aInterface.addType(aComplexTypeDef); } } else throw new IllegalStateException("Unhandled special type: " + sTypeName); } } // Add all methods for (final Map.Entry<String, JsonNode> aMethodEntry : _getAllChildren(aInterfaceNode).entrySet()) { final String sMethodName = aMethodEntry.getKey(); if (!sMethodName.startsWith("$")) { final ObjectNode aMethodNode = (ObjectNode) aMethodEntry.getValue(); final WGMethod aMethod = new WGMethod(sMethodName); // Input final JsonNode aInputNode = aMethodNode.get("$input"); if (aInputNode != null && aInputNode.isObject()) { aMethod.markHavingInput(); for (final Map.Entry<String, JsonNode> aEntry : _getAllChildren(aInputNode).entrySet()) { final String sParamName = aEntry.getKey(); final String sParamType = aEntry.getValue().asText(); final IWGType aParamType = aInterface.getTypeOfName(sParamType); if (aParamType == null) throw new IllegalArgumentException("Input type '" + sParamType + "' of method '" + sMethodName + "' for element '" + sParamName + "' not found"); aMethod.addInputParam(sParamName, aParamType); } } // Output final JsonNode aOutputNode = aMethodNode.get("$output"); if (aOutputNode != null && aOutputNode.isObject()) { aMethod.markHavingOutput(); for (final Map.Entry<String, JsonNode> aEntry : _getAllChildren(aOutputNode).entrySet()) { final String sParamName = aEntry.getKey(); final String sParamType = aEntry.getValue().asText(); final IWGType aParamType = aInterface.getTypeOfName(sParamType); if (aParamType == null) throw new IllegalArgumentException("Output type '" + sParamType + "' of method '" + sMethodName + "' for element '" + sParamName + "' not found"); aMethod.addOutputParam(sParamName, aParamType); } } // Fault final JsonNode aFaultNode = aMethodNode.get("$fault"); if (aFaultNode != null && aFaultNode.isObject()) { aMethod.markHavingFault(); for (final Map.Entry<String, JsonNode> aEntry : _getAllChildren(aFaultNode).entrySet()) { final String sParamName = aEntry.getKey(); final String sParamType = aEntry.getValue().asText(); final IWGType aParamType = aInterface.getTypeOfName(sParamType); if (aParamType == null) throw new IllegalArgumentException("Fault type '" + sParamType + "' of method '" + sMethodName + "' for element '" + sParamName + "' not found"); aMethod.addFaultParam(sParamName, aParamType); } } aInterface.addMethod(aMethod); } } return aInterface; }