[
https://issues.apache.org/jira/browse/AVRO-2897?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Mattias Andersson updated AVRO-2897:
------------------------------------
Description:
I apologize in advance if this is a misunderstanding of funcitonality on my
part and I have only tested it on the latest published npm package
([https://www.npmjs.com/package/avro-js]) but if not this should be a rather
serious bug.
According to multiple sources
([https://avro.apache.org/docs/1.8.1/spec.htm|https://avro.apache.org/docs/1.8.1/spec.html]),
nullable values should be specified as a unon with the type null, e.g. for
string "['null', 'string']"
However, given the following code (that from what I understand should be valid)
{code:java}
var type = avro.parse({
name: 'Pet',
type: 'record',
fields: [
{ name: 'name', type: ['null', 'string'] }
]
});
var pet = { name: "Fido" };
var buf = type.toBuffer(pet);
var obj = type.fromBuffer(buf);
console.log(obj);
{code}
I get the followin error on "type.toBuffer(pet)"
{code:java}
Error: invalid ["null","string"]: "Fido"
{code}
Curiously, if I instead set pet name as "null" instead of "Fido" everything
runs fine and returns a correct output given the input. Though this is not very
useful as the field still can not be changed to anything else beside null.
{code:java}
...
var pet = { name: null };
...
console.log(obj);{code}
{code:java}
Pet { name: null }
{code}
Expected behavior is that both string and null should be valid parameters
without throwing an exception.
was:
I apologize in advance if this is a misunderstanding of funcitonality on my
part and I have only tested it on the latest published npm package
([https://www.npmjs.com/package/avro-js]) but if not this should be a rather
serious bug.
According to multiple sources
([https://avro.apache.org/docs/1.8.1/spec.htm|https://avro.apache.org/docs/1.8.1/spec.html]),
nullable values should be specified as a unon with the type null, e.g. for
string "['null', 'string']"
However, given the following code (that from what I understand should be valid)
{code:java}
var type = avro.parse({
name: 'Pet',
type: 'record',
fields: [
{ name: 'name', type: ['null', 'string'] }
]
});
var pet = { name: "Fido" };
var buf = type.toBuffer(pet);
var obj = type.fromBuffer(buf);
console.log(obj);
{code}
I get the followin error on "type.toBuffer(pet)"
{code:java}
Error: invalid ["null","string"]: "Fido"
{code}
Curiously, if I instead set pet name as "null" instead of "Fido" everything
runs fine and returns a correct output given the input. Though this is not very
useful as the field still can not be changed to anything else beside null.
{code:java}
...
var pet = { name: null };
...
console.log(obj);{code}
{code:java}
Pet { name: null }
{code}
> Unable to create nullable fields in Avro JavaScript implementation
> ------------------------------------------------------------------
>
> Key: AVRO-2897
> URL: https://issues.apache.org/jira/browse/AVRO-2897
> Project: Apache Avro
> Issue Type: Bug
> Components: javascript
> Affects Versions: 1.10.0
> Reporter: Mattias Andersson
> Priority: Major
>
>
> I apologize in advance if this is a misunderstanding of funcitonality on my
> part and I have only tested it on the latest published npm package
> ([https://www.npmjs.com/package/avro-js]) but if not this should be a rather
> serious bug.
> According to multiple sources
> ([https://avro.apache.org/docs/1.8.1/spec.htm|https://avro.apache.org/docs/1.8.1/spec.html]),
> nullable values should be specified as a unon with the type null, e.g. for
> string "['null', 'string']"
> However, given the following code (that from what I understand should be
> valid)
> {code:java}
> var type = avro.parse({
> name: 'Pet',
> type: 'record',
> fields: [
> { name: 'name', type: ['null', 'string'] }
> ]
> });
> var pet = { name: "Fido" };
> var buf = type.toBuffer(pet);
> var obj = type.fromBuffer(buf);
> console.log(obj);
> {code}
> I get the followin error on "type.toBuffer(pet)"
> {code:java}
> Error: invalid ["null","string"]: "Fido"
> {code}
>
> Curiously, if I instead set pet name as "null" instead of "Fido" everything
> runs fine and returns a correct output given the input. Though this is not
> very useful as the field still can not be changed to anything else beside
> null.
> {code:java}
> ...
> var pet = { name: null };
> ...
> console.log(obj);{code}
> {code:java}
> Pet { name: null }
> {code}
>
> Expected behavior is that both string and null should be valid parameters
> without throwing an exception.
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)