Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

com.twitter.elephantbird.util.ThriftUtils unable to find fields with _ or - in its name #472

Open
krausb opened this issue Sep 14, 2016 · 0 comments

Comments

@krausb
Copy link

krausb commented Sep 14, 2016

In my current case the ThriftUtils.getFieldType(...) is not able to successful reflect a field named signal_name out of the thrift class.

Example thrift struct:

struct TSignal {
1: required i32 signalId
2: required string signal_name
3: required i64 timestamp
4: required i32 raw_value
5: required double physical_value
6: optional string note
}

The Problem here is, that the thrift compiler itself camel cases the getter and the setter to
TSignal.getSignalName and TSignal.setSignalName without _ or -.

On line 142 of latest Version of ThriftUtils.getFieldType(...) you are looking for:
Method method = containingClass.getDeclaredMethod(prefix + suffix);

The variable suffix evaluates as a result of line 135:
String suffix = // uppercase first letter fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
to "getSignal_name" or "isSignal_name" which does not exist in the thrift class.

Would be nice if you could recognize this behaviour and add that eventuality into ThriftUtils.getFieldType.

Possible solutions would be changing the discovery of the fields by using Class.getDeclaredField(...) so you would'nt need the prefix + suffix and may use the field name directly here or additionaly camel case the field name.

Regards,
Bastian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant