public Object(JsonNode n, NodeCursor p) { super(JsonStreamContext.TYPE_OBJECT, p); _contents = ((ObjectNode) n).getFields(); _needEntry = true; }
public Object(JsonNode n, NodeCursor p) { super(JsonStreamContext.TYPE_OBJECT, p); _contents = ((ObjectNode) n).getFields(); _needEntry = true; }
public Object(JsonNode n, NodeCursor p) { super(JsonStreamContext.TYPE_OBJECT, p); _contents = ((ObjectNode) n).getFields(); _needEntry = true; }
public Object(JsonNode n, NodeCursor p) { super(JsonStreamContext.TYPE_OBJECT, p); _contents = ((ObjectNode) n).getFields(); _needEntry = true; }
public Object(JsonNode n, NodeCursor p) { super(JsonStreamContext.TYPE_OBJECT, p); _contents = ((ObjectNode) n).getFields(); _needEntry = true; }
public class AnnotationDeserializer extends StdDeserializer<Annotation> { AnnotationDeserializer() { super(Annotation.class); } @Override public Annotation deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectMapper mapper = (ObjectMapper) jp.getCodec(); ObjectNode root = (ObjectNode) mapper.readTree(jp); Class<? extends Annotation> realClass = null; Iterator<Entry<String, JsonNode>> elementsIterator = root.getFields(); while (elementsIterator.hasNext()) { Entry<String, JsonNode> element = elementsIterator.next(); if ("type".equals(element.getKey())) { realClass = AnnotationObjectFactory.getInstance() .getAnnotationClass(element.getKey()); break; } } if (realClass == null) return null; return mapper.readValue(root, realClass); } }
Iterator<Entry<String, JsonNode>> iterator = root.getFields(); boolean found = false; while (!found &&iterator.hasNext()) {
public class MyDeserializer extends JsonDeserializer< Message > { @Override public Message deserialize( JsonParser jp, DeserializationContext arg1 ) throws IOException, JsonProcessingException { ObjectMapper mapper = (ObjectMapper) jp.getCodec(); ObjectNode root = (ObjectNode) mapper.readTree(jp); Class<? extends Message> subClass = null; Iterator<Entry<String, JsonNode>> elementsIterator = root.getFields(); while (elementsIterator.hasNext()) { Entry<String, JsonNode> element = elementsIterator.next(); String name = element.getKey(); if ("foo_id".equals(name)) { if(element.getValue().isInt()) subClass = FooInteger.Class; break; } } if (subClass == null) return null; return mapper.readValue(root, subClass); } }
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; }
@Override public Collection<? extends Entry<String, JzonElement>> entrySet() { HashSet<Entry<String, JzonElement>> jset = new HashSet<Entry<String, JzonElement>>(); for (Iterator<Entry<String, JsonNode>> i = wrapped.getFields(); i.hasNext();) { final Entry<String, JsonNode> e = i.next(); final JzonElement el = JacksonWrapper.wrap(e.getValue()); jset.add(new Entry<String, JzonElement>() { @Override public String getKey() { return e.getKey(); } @Override public JzonElement getValue() { return el; } @Override public JzonElement setValue(JzonElement value) { throw new UnsupportedOperationException(); } }); } return jset; }
/** * The generateFacetsForLeaves() method for processing json objects, delegates for each field and constructs path. */ private void generateFacetsForLeaves(ObjectNode object, String fieldName, ExtendedJsonField sirenField, String path, List<SirenFacetEntry> facets) { Iterator<Entry<String, JsonNode>> iterator = object.getFields(); while (iterator.hasNext()) { Entry<String, JsonNode> entry = iterator.next(); String field = entry.getKey(); JsonNode value = entry.getValue(); if (field.equals("_datatype_") || field.equals("_value_")) { generateFacetsForCustomDatatypeLeaf(object, fieldName, sirenField, path, facets); return; } generateFacetsForLeaves(value, fieldName, sirenField, path.isEmpty() ? field : path + "." + field, facets); } }
@Override public Collection<? extends Entry<String, JzonElement>> entrySet() { HashSet<Entry<String, JzonElement>> jset = new HashSet<Entry<String, JzonElement>>(); for (Iterator<Entry<String, JsonNode>> i = wrapped.getFields(); i.hasNext();) { final Entry<String, JsonNode> e = i.next(); final JzonElement el = JacksonWrapper.wrap(e.getValue()); jset.add(new Entry<String, JzonElement>() { @Override public String getKey() { return e.getKey(); } @Override public JzonElement getValue() { return el; } @Override public JzonElement setValue(JzonElement value) { throw new UnsupportedOperationException(); } }); } return jset; }
private void validatePatternProperties(ObjectNode node, JsonSchemaObjectNode schema, String path) throws JsonSchemaValidationException { // iterate through all patterns, and apply to every property for validation for (Map.Entry<Pattern, JsonSchemaObjectNode> patternSchema : schema.getPatternPropertySchemas().entrySet()) { Pattern keyPattern = patternSchema.getKey(); JsonSchemaObjectNode keySchema = patternSchema.getValue(); Iterator<Map.Entry<String, JsonNode>> fields = node.getFields(); while (fields.hasNext()) { Map.Entry<String, JsonNode> field = fields.next(); // check for a pattern match if (keyPattern.matcher(field.getKey()).matches()) { // this property matches the pattern, apply the schema validate(field.getValue(), keySchema, path); } } } } }
public static Configuration getHBaseConfiguration(ZooKeeperItf zk) { try { Configuration configuration = HBaseConfiguration.create(); // Make this configuration object 'owned' by us: this way we can close the associated // connection completely without worrying we close someone else's connection (e.g. // when running two LilyClient's in one JVM, or when running LilyClient from within // the lily-server JVM, which is the case when we launch a batch build job) configuration.set(HConstants.HBASE_CLIENT_INSTANCE_ID, String.valueOf("lilyclient-" + hbaseConfCounter.incrementAndGet())); byte[] data = zk.getData(hbaseConfigPath, false, new Stat()); ObjectNode propertiesNode = (ObjectNode) JsonFormat.deserializeSoft(data, "HBase configuration"); Iterator<Map.Entry<String, JsonNode>> it = propertiesNode.getFields(); while (it.hasNext()) { Map.Entry<String, JsonNode> entry = it.next(); configuration.set(entry.getKey(), entry.getValue().getTextValue()); } return configuration; } catch (Exception e) { throw new RuntimeException("Failed to get HBase configuration from ZooKeeper", e); } }
@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; }
public static Namespaces fromJson(ObjectNode nsNode) throws JsonFormatException { Namespaces namespaces = new NamespacesImpl(); Iterator<Map.Entry<String, JsonNode>> fieldsIt = nsNode.getFields(); while (fieldsIt.hasNext()) { Map.Entry<String, JsonNode> entry = fieldsIt.next(); String namespace = entry.getKey(); String prefix; if (!entry.getValue().isTextual()) { throw new JsonFormatException("Namespace property should map to a string prefix. Namespace: " + namespace); } else { prefix = entry.getValue().getTextValue(); } // addMapping will validate that the same prefix is not already bound to another namespace. namespaces.addMapping(prefix, namespace); } return namespaces; }
@Override public RecordVariantFilter fromJson(JsonNode node, Namespaces namespaces, LRepository repository, RecordFilterJsonConverter<RecordFilter> converter) throws JsonFormatException, RepositoryException, InterruptedException { String recordId = JsonUtil.getString(node, "recordId", null); if (recordId == null) { throw new IllegalStateException("expected non null recordId in json input"); } final ObjectNode variantPropertiesNode = JsonUtil.getObject(node, "variantProperties", null); if (variantPropertiesNode == null) { throw new IllegalStateException("expected non null variantProperties in json input"); } final HashMap<String, String> variantProperties = new HashMap<String, String>(); final Iterator<Map.Entry<String, JsonNode>> fields = variantPropertiesNode.getFields(); while (fields.hasNext()) { final Map.Entry<String, JsonNode> next = fields.next(); variantProperties.put(next.getKey(), next.getValue().getTextValue()); } return new RecordVariantFilter(repository.getIdGenerator().fromString(recordId), variantProperties); } }
Iterator<Map.Entry<String, JsonNode>> fields = on.getFields();
public IndexDefinition(String name, ObjectNode jsonObject) { this.name = name; if (jsonObject.get("identifierOrder") != null) { setIdentifierOrder(Order.valueOf(jsonObject.get("identifierOrder").getTextValue())); } else { setIdentifierOrder(Order.ASCENDING); } try { ObjectNode fields = (ObjectNode) jsonObject.get("fields"); Iterator<Map.Entry<String, JsonNode>> fieldsIt = fields.getFields(); while (fieldsIt.hasNext()) { Map.Entry<String, JsonNode> entry = fieldsIt.next(); String className = entry.getValue().get("class").getTextValue(); Class<IndexFieldDefinition> clazz = (Class<IndexFieldDefinition>) getClass().getClassLoader().loadClass(className); Constructor<IndexFieldDefinition> constructor = clazz.getConstructor(String.class, ObjectNode.class); IndexFieldDefinition field = constructor.newInstance(entry.getKey(), entry.getValue()); add(field); } } catch (Exception e) { throw new RuntimeException("Error instantiating IndexDefinition.", e); } }
public static FieldsMapperBean genQueryMapper(String json) { FieldsMapperBean fmb = new FieldsMapperBean(); ObjectNode node = JsonUtil.toObjectNode(json); Iterator<Map.Entry<String, JsonNode>> iter = node.getFields(); while (iter.hasNext()) { Entry<String, JsonNode> entry = iter.next(); String key = entry.getKey(); JsonNode value = entry.getValue(); SearchField sf = new SearchField(); sf.setFieldName(key); sf.setShow(value.asInt()); fmb.getFields().add(sf); } return fmb; } }