/** * Reads a table import mapping descriptor from its JSON serialized form. * * @param json JSON string. * @return the decoded table layout descriptor. * @throws IOException on I/O error. */ public static TableImportDescriptorDesc readTableImportDescriptorDescFromJSON(String json) throws IOException { final TableImportDescriptorDesc desc = (TableImportDescriptorDesc) FromJson.fromJsonString(json, TableImportDescriptorDesc.SCHEMA$); return desc; }
while (it.hasNext()) { final JsonNode element = it.next(); list.add(fromJsonNode(element, schema.getElementType())); while (it.hasNext()) { final Map.Entry<String, JsonNode> entry = it.next(); map.put(entry.getKey(), fromJsonNode(entry.getValue(), schema.getValueType())); final SpecificRecord record = newSpecificRecord(schema.getFullName()); for (Schema.Field field : schema.getFields()) { final String fieldName = field.name(); final JsonNode fieldElement = json.get(fieldName); if (fieldElement != null) { final Object fieldValue = fromJsonNode(fieldElement, field.schema()); record.put(field.pos(), fieldValue); } else if (field.defaultValue() != null) { record.put(field.pos(), fromJsonNode(field.defaultValue(), field.schema())); } else { throw new IOException(String.format( case UNION: return fromUnionJsonNode(json, schema); return enumValue(schema.getFullName(), enumValStr);
final Schema optionalType = AvroUtils.getOptionalType(schema); if (optionalType != null) { return json.isNull() ? null : fromJsonNode(json, optionalType); return fromJsonNode(actualNode, type); return fromJsonNode(json, type); } catch (IOException ioe) {
public FijiRowFilter createFromJson(JsonNode root) { try { final RowKeyFormat2 rowKeyFormat = (RowKeyFormat2) FromJson.fromAvroJsonString( root.path(ROW_KEY_FORMAT_NODE).getTextValue(), RowKeyFormat2.SCHEMA$); final JsonNode componentsJsonNode = root.path(COMPONENTS_NODE);
/** * Decodes a JSON encoded record. * * @param json JSON tree to decode, encoded as a string. * @param schema Avro schema of the value to decode. * @return the decoded value. * @throws IOException on error. */ public static Object fromJsonString(String json, Schema schema) throws IOException { final ObjectMapper mapper = new ObjectMapper(); final JsonParser parser = new JsonFactory().createJsonParser(json) .enable(Feature.ALLOW_COMMENTS) .enable(Feature.ALLOW_SINGLE_QUOTES) .enable(Feature.ALLOW_UNQUOTED_FIELD_NAMES); final JsonNode root = mapper.readTree(parser); return fromJsonNode(root, schema); }
/** {@inheritDoc} */ @Override public FijiRowFilter createFromJson(JsonNode root) { final String family = root.path(FAMILY_NODE).getTextValue(); final String qualifier = root.path(QUALIFIER_NODE).getTextValue(); final String schema = root.path(VALUE_NODE).path(SCHEMA_NODE).getTextValue(); final Schema writerSchema = (new Schema.Parser()).parse(schema); final String data = root.path(VALUE_NODE).path(DATA_NODE).getTextValue(); try { final DecodedCell<?> cell = new DecodedCell<Object>(writerSchema, FromJson.fromAvroJsonString(data, writerSchema)); return new ColumnValueEqualsRowFilter(family, qualifier, cell); } catch (IOException ioe) { throw new FijiIOException(ioe); } } }
/** * Reads a table layout descriptor from its JSON serialized form. * * @param istream JSON input stream. * @return the decoded table layout descriptor. * @throws IOException on I/O error. */ public static TableLayoutDesc readTableLayoutDescFromJSON(InputStream istream) throws IOException { final String json = IOUtils.toString(istream); final TableLayoutDesc desc = (TableLayoutDesc) FromJson.fromJsonString(json, TableLayoutDesc.SCHEMA$); return desc; }