Diagram of the Avro - optional fields - not give 'in the Union"exception

Hi all

I have a problem with the help of the optional fields in a schema by using the JSONAvroBinding and avro.

If I have a scheme of the user who has a first name field. The user may choose to provide the name or not. The field is optional from the perspective of readers.

(this comes from http://docs.oracle.com/cd/NOSQL/html/GettingStartedGuide/avroschemas.html who is nosql avro documentation)

{

"type': 'record."

"namespace": "com.example."

'name': 'Full name',

'fields':]

{'name': 'first', 'type': ['string', 'null']},

{'name': 'last', 'type': "string", "default": "Smith"}

]

}

Here, if I provide this example as Avro scheme, then omit the name when I write, it will work without problem. But when I try to write 'John' it will fail with:

Caused by: org.apache.avro.UnresolvedUnionException: not in the union ['string', 'null']: 'John '.

to oracle.kv.impl.api.avro.JsonBinding$ JsonData.resolveUnion (JsonBinding.java:403)

at org.apache.avro.generic.GenericDatumWriter.resolveUnion(GenericDatumWriter.java:144)

to oracle.kv.impl.api.avro.JsonBinding$ JsonDatumWriter.write (JsonBinding.java:599)

to oracle.kv.impl.api.avro.JsonBinding$ JsonDatumWriter.writeRecord (JsonBinding.java:695)

to oracle.kv.impl.api.avro.JsonBinding$ JsonDatumWriter.write (JsonBinding.java:565)

Truncated. check the log file full stacktrace

It does not work:

{

'first': 'John ',.

"last": "Smith".

}

It works:

{

"last": "Smith".

}

It seems that someone else has had this problem and posted on the Avro site, where a response said that it might be NoSQLs due to lack of libraries:

"The error is thrown from the Oracle NoSQL Avro library use and is not clearly a problem of Avro. You might be better off trying to get help for this Oracle? »

https://issues.Apache.org/jira/browse/Avro-1376

Any thoughts? To me, this seems to be a bug in the JsonBinding class?

According to this:

http://www.Oracle.com/technetwork/database/nosqldb/learnmore/nosqldb-FAQ-518364.html#HowtouseAvrounionstoencodeoptionalfields

Sending

{

'first': 'John ',.

"last": "Smith".

}

is not correct.

Instead, sending:

{

'first': {}

'chain': 'John '.

},

"last": "Smith".

}

works.

Tags: Database

Similar Questions

Maybe you are looking for