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

fix property case-handling during CRD gen #194

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

euberseder-hubspot
Copy link

We've noticed that Immutables doesn't follow the same case-conventions as Jackson in cases where the getter is something like getHBaseImage(). In that case, Immutables makes the field on the POJO hBaseImage and therefore that is the field name in the generated CRDs. Jackson expects the field name in that case to be hbaseImage, and therefore there's a deserialization error thrown with the field is required on the POJO.

This PR makes sure the field names follow the Jackson case-conventions unless overridden by the JsonProperty annotation.

@ndimiduk
Copy link

You're fixing this in our fork of fabric8, but isn't this an issue in Immutables not agreeing with Jackson?

@ndimiduk
Copy link

An alternate and completely reasonable solution would be an ErrorProne check that prevents these getFOoBar kind of property names in Immutables.

@euberseder-hubspot
Copy link
Author

You're fixing this in our fork of fabric8, but isn't this an issue in Immutables not agreeing with Jackson?

Our fork is a perfectly reasonable place to fix this issue. While it's not something I plan to push upstream, this doesn't just cover cases with Immutables. The internal deserialization in Fabric8 is done with Jackson, and any time the internal properties of a POJO fall into these casing edge cases, Jackson will fail to recognize the field match on deserialization.

An alternate and completely reasonable solution would be an ErrorProne check that prevents these getFOoBar kind of property names in Immutables.

This would cause a pretty large disruption to users, who currently have this sort of naming in their Immutables, but it's otherwise working just fine because they are not using generated CRD yaml yet. Names in interfaces would have to change, and existing objects in the API would have to be migrated. I don't think that's a tenable solution.

@ndimiduk
Copy link

I don't think it's a big deal to change these objects. the hardest part is having a period where both versions of the serialized form are accepted. i don't think this is a very common use-case. But as you like, if you prefer to fix it in our branch, sure.

@saiskee saiskee self-requested a review January 24, 2025 17:36
TypeRef typeRef = schemaFrom != null ? schemaFrom : parameterMap.exchange(original.getTypeRef());
String finalName = renamedTo != null ? renamedTo : original.getName();

return new Property(original.getAnnotations(), typeRef, finalName,
original.getComments(), false, false, original.getModifiers(), original.getAttributes());
}

private String getCaseCorrectedPropertyName() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment here describing what "case correction" in this case means?

@@ -517,7 +517,7 @@ public void process() {
break;
case ANNOTATION_JSON_PROPERTY:
final String nameFromAnnotation = (String) a.getParameters().get(VALUE);
if (!Strings.isNullOrEmpty(nameFromAnnotation) && !propertyName.equals(nameFromAnnotation)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test my understanding - this change is necessary because we want the nameFromAnnotation to override anything we might do from getCaseCorrectedPropertyName() ? Since if renamedTo is not null, the result of getCaseCorrectedPropertyName() is unused.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly. If someone actually wanted getHBaseImage() to generate a CRD field of hBaseImage instead of hbaseImage, then they should use JsonProperty to annotate that getter to override our default conversion, but if the internal field name was already hBaseImage (because maybe the field is generated with Immutables) then without this line setting that wouldn't be detected as an override and we'd use the new convention anyway.

@nhirakawa
Copy link
Collaborator

Makes sense to me, aside from a clarifying question

@euberseder-hubspot euberseder-hubspot merged commit ae1243d into 6.13.4-hubspot Jan 27, 2025
1 check passed
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

Successfully merging this pull request may close these issues.

4 participants