Parse() public static method

public static Parse ( string json ) : Schema
json string
return Schema
Example #1
0
        private GenericRecord CreateAvroRecord(string json, string avroSchema)
        {
            try
            {
                var schema = (RecordSchema)Schema.Parse(avroSchema);

                var jsonObject = jsonSerializer.Deserialize <JsonObject>(json);

                var result = (GenericRecord)GetValue(jsonObject, schema);

                return(result);
            }
            catch (JsonException ex)
            {
                throw new InvalidOperationException($"Failed to parse json: {json}, got {ex.Message}", ex);
            }
        }
Example #2
0
        static void GenSchema(string infile, string outdir)
        {
            try
            {
                var text   = System.IO.File.ReadAllText(infile);
                var schema = Schema.Parse(text);

                var codegen = new CodeGen();
                codegen.AddSchema(schema);

                codegen.GenerateCode();
                codegen.WriteTypes(outdir);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Concat("Exception occurred. ", ex.Message));
            }
        }
Example #3
0
        static void GenSchema(string infile, string outdir)
        {
            try
            {
                string text   = System.IO.File.ReadAllText(infile);
                Schema schema = Schema.Parse(text);

                CodeGen codegen = new CodeGen();
                codegen.AddSchema(schema);

                codegen.GenerateCode();
                codegen.WriteTypes(outdir);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception occurred. " + ex.Message);
            }
        }
Example #4
0
 private static void GenSchema(IEnumerable <string> infile, string outdir)
 {
     try
     {
         var codeGen    = new CodeGen();
         var schemaName = new SchemaNames();
         foreach (var str in infile)
         {
             var schema = Schema.Parse(System.IO.File.ReadAllText(str), schemaName);
             schemaName.Add(schema as NamedSchema);
             codeGen.AddSchema(schema);
         }
         codeGen.GenerateCode();
         codeGen.WriteTypes(outdir);
     }
     catch (Exception exception)
     {
         //Console.WriteLine(string.Concat("Exception occurred. ", exception.Message));
         throw new Exception(string.Concat("Exception occurred. ", exception.Message));
     }
 }
Example #5
0
        static void GenSchema(string infile, string outdir,
                              IEnumerable <KeyValuePair <string, string> > namespaceMapping)
        {
            try
            {
                string text   = System.IO.File.ReadAllText(infile);
                Schema schema = Schema.Parse(text);

                CodeGen codegen = new CodeGen();
                codegen.AddSchema(schema);

                foreach (var entry in namespaceMapping)
                {
                    codegen.NamespaceMapping[entry.Key] = entry.Value;
                }

                codegen.GenerateCode();
                codegen.WriteTypes(outdir);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception occurred. " + ex.Message);
            }
        }
Example #6
0
 /// <summary>
 /// Parses a given JSON string to create a new schema object
 /// </summary>
 /// <param name="json">JSON string</param>
 /// <returns>new Schema object</returns>
 public static Schema Parse(string json)
 {
     return(Schema.Parse(json, new SchemaNames()));
 }