Hi,

In that case you will need a field called 'DataModel' whose type is
'DataModel':

{
  "type" : "record",
  "name" : "ParentType",
  "fields" : [
    "name" : "DataModel",
    "type" : {
      "type" : "record",
      "name" : "DataModel",
      "fields" : [
  { "name" : "TMS_ID", "type" : "string", "default" : "NONE" }
  ]
    }
  ]
}

On 9 August 2017 at 20:46, Manish Mehndiratta <web.man...@gmail.com> wrote:

> Thank you, Elliot. This worked.
> If my json needs to include "DataModel":, then what changes do I need to
> make in my avsc file?
>
> Thanks,
> Manish
>
> On Wed, Aug 9, 2017 at 1:46 PM, Elliot West <tea...@gmail.com> wrote:
>
>> Try:
>>
>> {
>>   "TMS_ID" : "asdf"
>> }
>>
>> On Wed, 9 Aug 2017 at 19:22, Manish Mehndiratta <web.man...@gmail.com>
>> wrote:
>>
>>> Hi Team,
>>>
>>> I stripped out my avro schema file and json file to only one element and
>>> yet it continues to give me the same error.
>>>
>>> Exception in thread "main" *org.apache.avro.AvroTypeException: Expected
>>> field name not found*: TMS_ID
>>>
>>> *--- avsc file ---*
>>> {
>>>   "type" : "record",
>>>   "name" : "DataModel",
>>>   "fields" : [
>>> { "name" : "TMS_ID", "type" : "string", "default" : "NONE" }
>>> ]
>>> }
>>>
>>> *--- json file ---*
>>> {
>>>     "DataModel" :{
>>> "TMS_ID" : "asdf"
>>> }
>>> }
>>>
>>> *--- avro validation query ---*
>>> java -jar avro-tools-1.8.1.jar fromjson --schema-file
>>> TMSDataModelFlat.avsc 90573445988483.json > validated.avro
>>>
>>> *--- error ---*
>>> Exception in thread "main" org.apache.avro.AvroTypeException: Expected
>>> field name not found: TMS_ID
>>>         at org.apache.avro.io.JsonDecoder.doAction(JsonDecoder.java:477)
>>>         at org.apache.avro.io.parsing.Parser.advance(Parser.java:88)
>>>         at org.apache.avro.io.JsonDecoder.advance(JsonDecoder.java:139)
>>>         at org.apache.avro.io.JsonDecoder.readString(JsonDecoder.java:
>>> 219)
>>>         at org.apache.avro.io.JsonDecoder.readString(JsonDecoder.java:
>>> 214)
>>>         at org.apache.avro.io.ResolvingDecoder.readString(ResolvingDeco
>>> der.java:201)
>>>         at org.apache.avro.generic.GenericDatumReader.readString(Generi
>>> cDatumReader.java:430)
>>>         at org.apache.avro.generic.GenericDatumReader.readString(Generi
>>> cDatumReader.java:422)
>>>         at org.apache.avro.generic.GenericDatumReader.readWithoutConver
>>> sion(GenericDatumReader.java:180)
>>>         at org.apache.avro.generic.GenericDatumReader.read(GenericDatum
>>> Reader.java:152)
>>>         at org.apache.avro.generic.GenericDatumReader.readField(Generic
>>> DatumReader.java:240)
>>>         at org.apache.avro.generic.GenericDatumReader.readRecord(Generi
>>> cDatumReader.java:230)
>>>         at org.apache.avro.generic.GenericDatumReader.readWithoutConver
>>> sion(GenericDatumReader.java:174)
>>>         at org.apache.avro.generic.GenericDatumReader.read(GenericDatum
>>> Reader.java:152)
>>>         at org.apache.avro.generic.GenericDatumReader.read(GenericDatum
>>> Reader.java:144)
>>>         at org.apache.avro.tool.DataFileWriteTool.run(DataFileWriteTool
>>> .java:99)
>>>         at org.apache.avro.tool.Main.run(Main.java:87)
>>>         at org.apache.avro.tool.Main.main(Main.java:76)
>>>
>>>
>>>
>

Reply via email to