You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Karthik Sampath Kumar <ka...@gmail.com> on 2012/01/05 09:31:09 UTC
Deprecation warnings in generated source code
I have 2 fields in .avsc file
{"name": "name", "type": "string"},
{"name": "email", "type": "string"},
I get the following in generated source code. Why does it contain *
@Deprecated* on the generated source code?
* @Deprecated* public java.lang.CharSequence name;
*@Deprecated* public java.lang.CharSequence email;
It occurs only in version* 1.6.1 *of the avro-maven-plugin
This doesn't happen when I use the 1.5.1 version
Re: Deprecation warnings in generated source code
Posted by Scott Carey <sc...@apache.org>.
In addition to giving deprecation warnings in code that uses the
deprecated fields, the generated source files themselves generate warnings.
It would be nice if we had three code generation options configurable in
the maven plugin:
<fieldVisibility>public<fieldVisibility> [For those that still would
like public member field access]
<fieldVisibility>public-deprecated<fieldVisibility> [For migrating
from public to private, default for now]
<fieldVisibility>private<fieldVisibility> [For those that want fields
hidden, possible future default]
I would move my current code to use 'public' because I don't yet want to
migrate to the builder since it is too slow currently, and I already have
wrapper classes hiding the fields from user code so it is of little use
for my legacy code. When I migrate to private it would be nice to
temporarily use the deprecated option beforehand, but right now it is just
cluttering my build with several hundred deprecated warning messages.
I have created a ticket for the above.
https://issues.apache.org/jira/browse/AVRO-988
We can also improve the performance of the builder, using bitmasks/BitSet
instead of byte[] for detecting when a field is set, along with fixing
AVRO-985.
https://issues.apache.org/jira/browse/AVRO-989
On 1/5/12 1:17 AM, "James Baldassari" <jb...@gmail.com> wrote:
>Hi,
>
>Since the Builder API was introduced (AVRO-839
><https://issues.apache.org/jira/browse/AVRO-839> released in v1.6.0),
>direct access to record fields has been deprecated. In some future
>version of Avro these fields will probably be made private. The
>preferred way to access the fields in Avro 1.6.0 and later is to use the
>associated getter/setter methods on the record or to use the Builder API.
> For example, if your record is called Person, you could do either of the
>following:
>
>// Use of accessor/mutator:
>Person me = new Person();
>me.setName("James");
>me.setEmail("root@localhost");
>System.out.println(me.getName());
>
>// Use of Builder:
>Person me2 =
>Person.newBuilder().setName("James").setEmail("root@localhost").build();
>System.out.println(me.getEmail());
>
>There is a bit of a performance penalty with using the builder, but
>hopefully that will be reduced somewhat when AVRO-985
><https://issues.apache.org/jira/browse/AVRO-985> is resolved.
>
>-James
>
>
>On Thu, Jan 5, 2012 at 3:31 AM, Karthik Sampath Kumar <ka...@gmail.com>
>wrote:
>
>I have 2 fields in .avsc file
>
> {"name": "name", "type": "string"},
> {"name": "email", "type": "string"},
>
>
>I get the following in generated source code. Why does it contain
>@Deprecated on the generated source code?
>
> @Deprecated public java.lang.CharSequence name;
> @Deprecated public java.lang.CharSequence email;
>
>
>
>It occurs only in version 1.6.1 of the avro-maven-plugin
>This doesn't happen when I use the 1.5.1 version
>
>
>
>
Re: Deprecation warnings in generated source code
Posted by James Baldassari <jb...@gmail.com>.
Hi,
Since the Builder API was introduced
(AVRO-839<https://issues.apache.org/jira/browse/AVRO-839>released in
v1.6.0), direct access to record fields has been deprecated.
In some future version of Avro these fields will probably be made private.
The preferred way to access the fields in Avro 1.6.0 and later is to use
the associated getter/setter methods on the record or to use the Builder
API. For example, if your record is called Person, you could do either of
the following:
// Use of accessor/mutator:
Person me = new Person();
me.setName("James");
me.setEmail("root@localhost");
System.out.println(me.getName());
// Use of Builder:
Person me2 = Person.newBuilder().setName("James").setEmail("root@localhost
").build();
System.out.println(me.getEmail());
There is a bit of a performance penalty with using the builder, but
hopefully that will be reduced somewhat when
AVRO-985<https://issues.apache.org/jira/browse/AVRO-985>is resolved.
-James
On Thu, Jan 5, 2012 at 3:31 AM, Karthik Sampath Kumar <ka...@gmail.com>wrote:
> I have 2 fields in .avsc file
>
> {"name": "name", "type": "string"},
> {"name": "email", "type": "string"},
>
> I get the following in generated source code. Why does it contain *
> @Deprecated* on the generated source code?
>
> * @Deprecated* public java.lang.CharSequence name;
> *@Deprecated* public java.lang.CharSequence email;
>
> It occurs only in version* 1.6.1 *of the avro-maven-plugin
> This doesn't happen when I use the 1.5.1 version
>
>
>