You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@beam.apache.org by Cristian Constantinescu <ze...@gmail.com> on 2021/09/12 16:16:35 UTC

Schemas with uppercase fields in beans

Hey all,

I might have found a bug in the way we create schemas from Java Beans.

My schema has to have uppercase field names.

So I have something like :

@DefaultSchema(JavaBeanSchema.class)
public class Foo {
private String ACTION_ID;

private String getACTION_ID(){..}
private void  setACTION_ID(String ACTION_ID){..}
}

Problem is that once the schema is parsed, all the fields have their first
letter lowercased. I think it's because of the ReflectUtils.stripPrefix
method.

As workarounds, I have tried:

1. Decorate my class with @SchemaCaseFormat(CaseFormat.UPPER_UNDERSCORE)
and have my fields/getters/setters follow camelCase naming. Unfortunately,
JavaBeanUtils.validateJavaBean sees all the setters as NULL. I'm not sure
why. I could investigate after I deliver a few things.

2. Use AutoValue. Unfortunately with Flink, I get things like this: Failed
to access class package.AutoValue_Foo$Builder from class
package.SchemaUserTypeCreator@SchemaCodeGen$someRandomString
package.AutoValue_Foo$Builder is in unnamed module of loader 'app';
package.SchemaUserTypeCreator@SchemaCodeGen$someRandomString is in
unnamed module of loader org.apache.flink.util.ChildFirstClassLoader . I
would love for this to work. Very sad it doesn't.

3. Use Pojos with @DefaultSchema(JavaFieldSchema.class), this seems to work
as expected, not 100% sure yet.

If this is indeed a bug, could someone create a Jira and I could have a
look into it in the near future.

Thanks,
Cristian

Re: Schemas with uppercase fields in beans

Posted by Cristian Constantinescu <ze...@gmail.com>.
Hey Brian,

I can't remember exactly, I think that's exactly what I did in point #1 but
forgot to mention that I also decorated with
@DefaultSchema(JavaBeanSchema.class) . So to be clear, I used both
@DefaultSchema(JavaBeanSchema.class) and
@SchemaCaseFormat(CaseFormat.UPPER_UNDERSCORE) and got null getters/setters.

I can write up a small project to illustrate the scenarios and confirm
exactly how things work.

On Tue, Sep 28, 2021 at 2:00 PM Brian Hulette <bh...@google.com> wrote:

> > 1. Decorate my class with @SchemaCaseFormat(CaseFormat.UPPER_UNDERSCORE)
> and have my fields/getters/setters follow camelCase naming. Unfortunately,
> JavaBeanUtils.validateJavaBean sees all the setters as NULL. I'm not sure
> why. I could investigate after I deliver a few things.
>
> I think this is what you need, your use-case sounds like the exact case
> that SchemaCaseFormat was created for. Did you try using
> @SchemaCaseFormat(CaseFormat.UPPER_UNDERSCORE) in conjunction with
> camel-cased getters/setters, i.e.:
>
> @DefaultSchema(JavaBeanSchema.class)
> @SchemaCaseFormat(CaseFormat.UPPER_UNDERSCORE)
> public class Foo {
>   public String getActionId(){..}
>   private void  setActionId(String actionId){..}
> }
>
> Brian
>
> On Sun, Sep 12, 2021 at 9:16 AM Cristian Constantinescu <ze...@gmail.com>
> wrote:
>
>> Hey all,
>>
>> I might have found a bug in the way we create schemas from Java Beans.
>>
>> My schema has to have uppercase field names.
>>
>> So I have something like :
>>
>> @DefaultSchema(JavaBeanSchema.class)
>> public class Foo {
>> private String ACTION_ID;
>>
>> private String getACTION_ID(){..}
>> private void  setACTION_ID(String ACTION_ID){..}
>> }
>>
>> Problem is that once the schema is parsed, all the fields have their
>> first letter lowercased. I think it's because of the
>> ReflectUtils.stripPrefix method.
>>
>> As workarounds, I have tried:
>>
>> 1. Decorate my class with @SchemaCaseFormat(CaseFormat.UPPER_UNDERSCORE)
>> and have my fields/getters/setters follow camelCase naming. Unfortunately,
>> JavaBeanUtils.validateJavaBean sees all the setters as NULL. I'm not sure
>> why. I could investigate after I deliver a few things.
>>
>> 2. Use AutoValue. Unfortunately with Flink, I get things like this:
>> Failed to access class package.AutoValue_Foo$Builder from class
>> package.SchemaUserTypeCreator@SchemaCodeGen$someRandomString
>> package.AutoValue_Foo$Builder is in unnamed module of loader 'app';
>> package.SchemaUserTypeCreator@SchemaCodeGen$someRandomString is in
>> unnamed module of loader org.apache.flink.util.ChildFirstClassLoader . I
>> would love for this to work. Very sad it doesn't.
>>
>> 3. Use Pojos with @DefaultSchema(JavaFieldSchema.class), this seems to
>> work as expected, not 100% sure yet.
>>
>> If this is indeed a bug, could someone create a Jira and I could have a
>> look into it in the near future.
>>
>> Thanks,
>> Cristian
>>
>

Re: Schemas with uppercase fields in beans

Posted by Brian Hulette <bh...@google.com>.
> 1. Decorate my class with @SchemaCaseFormat(CaseFormat.UPPER_UNDERSCORE)
and have my fields/getters/setters follow camelCase naming. Unfortunately,
JavaBeanUtils.validateJavaBean sees all the setters as NULL. I'm not sure
why. I could investigate after I deliver a few things.

I think this is what you need, your use-case sounds like the exact case
that SchemaCaseFormat was created for. Did you try using
@SchemaCaseFormat(CaseFormat.UPPER_UNDERSCORE) in conjunction with
camel-cased getters/setters, i.e.:

@DefaultSchema(JavaBeanSchema.class)
@SchemaCaseFormat(CaseFormat.UPPER_UNDERSCORE)
public class Foo {
  public String getActionId(){..}
  private void  setActionId(String actionId){..}
}

Brian

On Sun, Sep 12, 2021 at 9:16 AM Cristian Constantinescu <ze...@gmail.com>
wrote:

> Hey all,
>
> I might have found a bug in the way we create schemas from Java Beans.
>
> My schema has to have uppercase field names.
>
> So I have something like :
>
> @DefaultSchema(JavaBeanSchema.class)
> public class Foo {
> private String ACTION_ID;
>
> private String getACTION_ID(){..}
> private void  setACTION_ID(String ACTION_ID){..}
> }
>
> Problem is that once the schema is parsed, all the fields have their first
> letter lowercased. I think it's because of the ReflectUtils.stripPrefix
> method.
>
> As workarounds, I have tried:
>
> 1. Decorate my class with @SchemaCaseFormat(CaseFormat.UPPER_UNDERSCORE)
> and have my fields/getters/setters follow camelCase naming. Unfortunately,
> JavaBeanUtils.validateJavaBean sees all the setters as NULL. I'm not sure
> why. I could investigate after I deliver a few things.
>
> 2. Use AutoValue. Unfortunately with Flink, I get things like this: Failed
> to access class package.AutoValue_Foo$Builder from class
> package.SchemaUserTypeCreator@SchemaCodeGen$someRandomString
> package.AutoValue_Foo$Builder is in unnamed module of loader 'app';
> package.SchemaUserTypeCreator@SchemaCodeGen$someRandomString is in
> unnamed module of loader org.apache.flink.util.ChildFirstClassLoader . I
> would love for this to work. Very sad it doesn't.
>
> 3. Use Pojos with @DefaultSchema(JavaFieldSchema.class), this seems to
> work as expected, not 100% sure yet.
>
> If this is indeed a bug, could someone create a Jira and I could have a
> look into it in the near future.
>
> Thanks,
> Cristian
>