Skip to content

Ensure that HubSpot style will pass rosetta annotations into Immutables #55

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

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion hubspot-style/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
<dependency>
<groupId>com.hubspot.rosetta</groupId>
<artifactId>RosettaAnnotations</artifactId>
<scope>test</scope>
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit of an unfortunate dependency to pick up, do you think this can go away at some point in the future or are we stuck with it forever?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we can get away with a @Inherited tag on the RosettaAnnotation, trying that out now....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, that did not work. looks like its unavoidable to include @RosettaAnnotation in hubspot-immutables or something like @ImmutableInherited (from hubspot-immutables) into Rosetta. We could seperate out the RosettaAnnotation annotation into a seperate RosettaAnnotationsBase module, to cut down on the dependency size? 🤷

Copy link
Member

@jhaber jhaber Jun 10, 2024

Choose a reason for hiding this comment

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

I'm less worried about the size of the dep tree, moreso just feels weird to take a hard dependency on Rosetta here. But if it can't be avoided I guess we can just go with it

</dependency>
<dependency>
<groupId>com.hubspot.rosetta</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.hubspot.immutable.collection.encoding.ImmutableMapEncodingEnabled;
import com.hubspot.immutable.collection.encoding.ImmutableSetEncodingEnabled;
import com.hubspot.immutables.validation.InvalidImmutableStateException;
import com.hubspot.rosetta.annotations.RosettaAnnotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down Expand Up @@ -34,7 +35,7 @@
optionalAcceptNullable = true, // allow for an Optional<T> to have a setter that takes a null value of T
forceJacksonPropertyNames = false, // otherwise we can't use RosettaNamingStrategies
visibility = ImplementationVisibility.SAME, // Generated class will have the same visibility as the abstract class/interface)
passAnnotations = ImmutableInherited.class
passAnnotations = { ImmutableInherited.class, RosettaAnnotation.class }
)
@ImmutableSetEncodingEnabled
@ImmutableListEncodingEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.hubspot.immutables.validation.InvalidImmutableStateException;
import com.hubspot.rosetta.annotations.RosettaAnnotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -22,7 +23,7 @@
forceJacksonPropertyNames = false, // otherwise we can't use RosettaNamingStrategies
visibility = ImplementationVisibility.SAME, // Generated class will have the same visibility as the abstract class/interface)
jdkOnly = true, // For Guava 18+, this stops MoreObjects from being used in toString and ImmutableHashMap.Builder from being used for building map fields (among other effects).
passAnnotations = ImmutableInherited.class
passAnnotations = { ImmutableInherited.class, RosettaAnnotation.class }
)
public @interface HubSpotModifiableStyle {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.hubspot.immutables.validation.InvalidImmutableStateException;
import com.hubspot.rosetta.annotations.RosettaAnnotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -25,7 +26,7 @@
forceJacksonPropertyNames = false, // otherwise we can't use RosettaNamingStrategies
visibility = ImplementationVisibility.SAME, // Generated class will have the same visibility as the abstract class/interface)
jdkOnly = true, // For Guava 18+, this stops MoreObjects from being used in toString and ImmutableHashMap.Builder from being used for building map fields (among other effects).
passAnnotations = ImmutableInherited.class
passAnnotations = { ImmutableInherited.class, RosettaAnnotation.class }
)
public @interface HubSpotStyle {
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void itThrowsInvalidStateOnValidation() {
@Test
public void itDeserializesJson() throws IOException {
String inputJson =
"{\"id\":1,\"hubSpotId\":12,\"name\":\"test\",\"somethingWithLongName\":\"a long thing\",\"blueSprocket\":true}";
"{\"id\":1,\"hubSpotId\":12,\"name\":\"test\",\"somethingWithLongName\":\"a long thing\",\"blueSprocket\":true,\"hubspotCustomName\":13}";
RosettaSprocket rosettaSprocket = objectMapper.readValue(
inputJson,
RosettaSprocket.class
Expand All @@ -84,6 +84,7 @@ public void itDeserializesJson() throws IOException {
assertThat(rosettaSprocket.getName()).isEqualTo("test");
assertThat(rosettaSprocket.getSomethingWithLongName()).isEqualTo("a long thing");
assertThat(rosettaSprocket.isBlueSprocket()).isTrue();
assertThat(rosettaSprocket.getCustomName()).isEqualTo(13);

JsonNode output = objectMapper.valueToTree(rosettaSprocket);
JsonNode original = objectMapper.readTree(inputJson);
Expand All @@ -93,7 +94,7 @@ public void itDeserializesJson() throws IOException {
@Test
public void itDeserializesRosettaJson() throws IOException {
String inputJson =
"{\"id\":1,\"hubspot_id\":12,\"name\":\"test\",\"something_with_long_name\":\"a long thing\",\"blue_sprocket\":true}";
"{\"id\":1,\"hubspot_id\":12,\"name\":\"test\",\"something_with_long_name\":\"a long thing\",\"blue_sprocket\":true,\"hubspot_custom_name\":13}";
RosettaSprocket rosettaSprocket = Rosetta
.getMapper()
.readValue(inputJson, RosettaSprocket.class);
Expand All @@ -102,6 +103,7 @@ public void itDeserializesRosettaJson() throws IOException {
assertThat(rosettaSprocket.getName()).isEqualTo("test");
assertThat(rosettaSprocket.getSomethingWithLongName()).isEqualTo("a long thing");
assertThat(rosettaSprocket.isBlueSprocket()).isTrue();
assertThat(rosettaSprocket.getCustomName()).isEqualTo(13);

JsonNode output = Rosetta.getMapper().valueToTree(rosettaSprocket);
JsonNode original = Rosetta.getMapper().readTree(inputJson);
Expand All @@ -111,7 +113,7 @@ public void itDeserializesRosettaJson() throws IOException {
@Test
public void itDeserializesAnInterface() throws IOException {
String inputJson =
"{\"id\":1,\"hubSpotId\":12,\"name\":\"test\",\"somethingWithLongName\":\"a long thing\",\"blueSprocket\":true}";
"{\"id\":1,\"hubSpotId\":12,\"name\":\"test\",\"somethingWithLongName\":\"a long thing\",\"blueSprocket\":true,\"hubspotCustomName\":13}";
RosettaSprocketIF rosettaSprocketIF = objectMapper.readValue(
inputJson,
RosettaSprocketIF.class
Expand All @@ -121,6 +123,7 @@ public void itDeserializesAnInterface() throws IOException {
assertThat(rosettaSprocketIF.getName()).isEqualTo("test");
assertThat(rosettaSprocketIF.getSomethingWithLongName()).isEqualTo("a long thing");
assertThat(rosettaSprocketIF.isBlueSprocket()).isTrue();
assertThat(rosettaSprocketIF.getCustomName()).isEqualTo(13);

JsonNode output = objectMapper.valueToTree(rosettaSprocketIF);
JsonNode original = objectMapper.readTree(inputJson);
Expand All @@ -130,7 +133,7 @@ public void itDeserializesAnInterface() throws IOException {
@Test
public void itDeserializesAnInterfaceFromRosetta() throws IOException {
String inputJson =
"{\"id\":1,\"hubspot_id\":12,\"name\":\"test\",\"something_with_long_name\":\"a long thing\",\"blue_sprocket\":true}";
"{\"id\":1,\"hubspot_id\":12,\"name\":\"test\",\"something_with_long_name\":\"a long thing\",\"blue_sprocket\":true,\"hubspot_custom_name\":13}";
RosettaSprocketIF rosettaSprocketIF = Rosetta
.getMapper()
.readValue(inputJson, RosettaSprocketIF.class);
Expand All @@ -139,6 +142,7 @@ public void itDeserializesAnInterfaceFromRosetta() throws IOException {
assertThat(rosettaSprocketIF.getName()).isEqualTo("test");
assertThat(rosettaSprocketIF.getSomethingWithLongName()).isEqualTo("a long thing");
assertThat(rosettaSprocketIF.isBlueSprocket()).isTrue();
assertThat(rosettaSprocketIF.getCustomName()).isEqualTo(13);

JsonNode output = Rosetta.getMapper().valueToTree(rosettaSprocketIF);
JsonNode original = Rosetta.getMapper().readTree(inputJson);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hubspot.immutables.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.hubspot.immutables.style.HubSpotStyle;
Expand All @@ -17,6 +18,10 @@ public interface RosettaSprocketIF {
@RosettaProperty("hubspot_id")
int getHubSpotId();

@JsonProperty("hubspotCustomName")
@RosettaProperty("hubspot_custom_name")
int getCustomName();

String getName();
String getSomethingWithLongName();
boolean isBlueSprocket();
Expand Down