@Override protected void _depositSchemaProperty(ObjectNode propertiesNode, JsonNode schemaNode) { JsonNode props = schemaNode.get("properties"); if (props != null) { Iterator<Entry<String, JsonNode>> it = props.fields(); while (it.hasNext()) { Entry<String,JsonNode> entry = it.next(); String name = entry.getKey(); if (_nameTransformer != null) { name = _nameTransformer.transform(name); } propertiesNode.set(name, entry.getValue()); } } }
@Override public ExposedPort deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); if (!node.equals(NullNode.getInstance())) { Entry<String, JsonNode> field = node.fields().next(); return ExposedPort.parse(field.getKey()); } else { return null; } } }
/** * Transforms the {@link JsonNode} into a map to integrate with the {@link SignatureChecker} utility. * * @param messageJson JSON of message. * @return Transformed map. */ private Map<String, String> toMap(JsonNode messageJson) { Map<String, String> fields = new HashMap<String, String>(messageJson.size()); Iterator<Map.Entry<String, JsonNode>> jsonFields = messageJson.fields(); while (jsonFields.hasNext()) { Map.Entry<String, JsonNode> next = jsonFields.next(); fields.put(next.getKey(), next.getValue().asText()); } return fields; }
@Override public VolumeRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); if (!node.equals(NullNode.getInstance())) { Entry<String, JsonNode> field = node.fields().next(); String volume = field.getKey(); AccessMode accessMode = AccessMode.fromBoolean(field.getValue().asBoolean()); return new VolumeRW(new Volume(volume), accessMode); } else { return null; } } }
private Map<String, JsonNode> parseAsJson(byte[] value) throws IOException { JsonNode document = mapper.readValue(value, JsonNode.class); //Hive Column names are case insensitive. Map<String, JsonNode> documentMap = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER); document.fields().forEachRemaining(field -> documentMap.put(field.getKey().toLowerCase(), field.getValue())); return documentMap; }
private Map.Entry<String, JsonNode> findAuthNode(final JsonNode config, final String reposName) { final JsonNode auths = config.get("auths"); if (auths != null && auths.size() > 0) { final Iterator<Map.Entry<String, JsonNode>> fields = auths.fields(); while (fields.hasNext()) { final Map.Entry<String, JsonNode> entry = fields.next(); if (entry.getKey().contains("://" + reposName) || entry.getKey().equals(reposName)) { return entry; } } } return null; }
public List<PageItem> loadItems(InputStream stream) throws IOException { JsonNode jsonTree = mapper.readTree(stream); List<PageItem> items = new LinkedList<>(); jsonTree.get("items").fields().forEachRemaining(itemEntry -> { items.add(new PageItem(itemEntry.getKey(), readArea(itemEntry.getValue()))); }); return items; }
private String getChildCiKey(JsonNode parent, String fieldName) { fieldName = fieldName.toUpperCase(); Iterator<Entry<String, JsonNode>> fields = parent.fields(); while (fields.hasNext()) { Entry<String, JsonNode> f = fields.next(); if (fieldName.equalsIgnoreCase(f.getKey())) { return f.getKey(); } } return fieldName; }
public Set<IndexStatistics> getIndicesStats(final Collection<String> indices) { final ImmutableSet.Builder<IndexStatistics> result = ImmutableSet.builder(); final JsonNode allWithShardLevel = getAllWithShardLevel(indices); final Iterator<Map.Entry<String, JsonNode>> fields = allWithShardLevel.fields(); while (fields.hasNext()) { final Map.Entry<String, JsonNode> entry = fields.next(); final String index = entry.getKey(); final JsonNode indexStats = entry.getValue(); if (indexStats.isObject()) { result.add(buildIndexStatistics(index, indexStats)); } } return result.build(); }
@Override public RedisStateMap deserialize(final byte[] data) throws IOException { if (data == null || data.length == 0) { return null; } final RedisStateMap.Builder builder = new RedisStateMap.Builder(); try (final JsonParser jsonParser = jsonFactory.createParser(data)) { final JsonNode rootNode = jsonParser.readValueAsTree(); builder.version(rootNode.get(FIELD_VERSION).asLong()); builder.encodingVersion(rootNode.get(FIELD_ENCODING).asInt()); final JsonNode stateValuesNode = rootNode.get(FIELD_STATE_VALUES); stateValuesNode.fields().forEachRemaining(e -> builder.stateValue(e.getKey(), e.getValue().asText())); } return builder.build(); }
private List<String> getColumnMetadata(Optional<String> parent, JsonNode propertiesNode) { ImmutableList.Builder<String> metadata = ImmutableList.builder(); Iterator<Entry<String, JsonNode>> iterator = propertiesNode.fields(); while (iterator.hasNext()) { Entry<String, JsonNode> entry = iterator.next(); String key = entry.getKey(); JsonNode value = entry.getValue(); String childKey; if (parent.isPresent()) { if (parent.get().isEmpty()) { childKey = key; } else { childKey = parent.get().concat(".").concat(key); } } else { childKey = key; } if (value.isObject()) { metadata.addAll(getColumnMetadata(Optional.of(childKey), value)); continue; } if (!value.isArray()) { metadata.add(childKey.concat(":").concat(value.textValue())); } } return metadata.build(); }
final Spliterator<Map.Entry<String, JsonNode>> fieldSpliterator = Spliterators.spliteratorUnknownSize(properties.fields(), Spliterator.IMMUTABLE); .map(field -> Maps.immutableEntry(field.getKey(), field.getValue().path("type").asText())) .filter(field -> !field.getValue().isEmpty()) .map(field -> FieldTypeDTO.create(field.getKey(), field.getValue())) .collect(Collectors.toSet());
@Override public Object deserialize(JsonNode n, ObjectMapper mapper) { HashMap<String, Object> o = new HashMap<String,Object>(); try { logger.debug("using custom map deserializer"); Iterator<Entry<String, JsonNode>> e = n.fields(); while(e.hasNext()) { Entry<String, JsonNode> ee = e.next(); o.put(ee.getKey(), parent.deserialize(ee.getValue(),mapper)); } } catch (Exception e) { logger.error("exception deserializing Map ", e); o = null; } return o; }
/** * Generates a list of condition from the Json node. * * @param conditionNodes * the condition Json node to be parsed. * @return the list of conditions. */ private List<Condition> conditionsOf(JsonNode conditionNodes) { List<Condition> conditionList = new LinkedList<Condition>(); Iterator<Map.Entry<String, JsonNode>> mapOfConditions = conditionNodes .fields(); Entry<String, JsonNode> condition; while (mapOfConditions.hasNext()) { condition = mapOfConditions.next(); convertConditionRecord(conditionList, condition.getKey(), condition.getValue()); } return conditionList; }
private static List<ShardRouting> buildShardRoutings(JsonNode shardRoutings) { final ImmutableList.Builder<ShardRouting> shardRoutingsBuilder = ImmutableList.builder(); final Iterator<Map.Entry<String, JsonNode>> it = shardRoutings.fields(); while (it.hasNext()) { final Map.Entry<String, JsonNode> entry = it.next(); final int shardId = Integer.parseInt(entry.getKey()); final JsonNode shards = entry.getValue();
/** This converts everything to Strings and back, but it does work, and avoids a bunch of type conditionals. */ public T scrape(JsonNode rootNode) { Map<String, String> pairs = Maps.newHashMap(); // Ugh, there has to be a better way to do this. Iterator<Map.Entry<String, JsonNode>> fieldIterator = rootNode.fields(); while (fieldIterator.hasNext()) { Map.Entry<String, JsonNode> field = fieldIterator.next(); pairs.put(field.getKey(), field.getValue().asText()); } return scrape(pairs); }
@Override public Object deserialize(JsonNode n, ObjectMapper mapper) { HashMap<String, Object> map = new HashMap<String, Object>(); Iterator<Map.Entry<String, JsonNode>> entries = n.fields(); while (entries.hasNext()) { try { Map.Entry<String, JsonNode> ee = entries.next(); map.put(ee.getKey(), parent.deserialize(ee.getValue(), mapper)); } catch (Exception e) { LoggerFactory.getLogger(this.getClass().getName()).error(e.getMessage()); } } return PersistentArrayMap.create(map); } }
@Override public YoBitOrderBooksReturn deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { JsonNode node = p.readValueAsTree(); Map<String, YoBitOrderBook> tickers = new HashMap<>(); if (node.isObject()) { Iterator<Map.Entry<String, JsonNode>> priceEntryIter = node.fields(); while (priceEntryIter.hasNext()) { Map.Entry<String, JsonNode> priceEntryNode = priceEntryIter.next(); JsonNode jsonNode = priceEntryNode.getValue(); ObjectReader jsonObjectReader = new ObjectMapper().readerFor(YoBitOrderBook.class); YoBitOrderBook orderBook = jsonObjectReader.readValue(jsonNode); String ccy = priceEntryNode.getKey(); tickers.put(ccy, orderBook); } } return new YoBitOrderBooksReturn(tickers); } }