Skip to content

Commit

Permalink
Merge pull request #107 from HubSpot/retarget_code
Browse files Browse the repository at this point in the history
Pin the release target to jdk8
  • Loading branch information
suruuK authored Jun 13, 2024
2 parents 2569dfe + 169d695 commit 4cfd9bb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.hubspot.rosetta.annotations.RosettaValue;
import com.hubspot.rosetta.annotations.StoredAsJson;
import java.util.Optional;
import java.util.function.Supplier;

public class RosettaAnnotationIntrospector extends NopAnnotationIntrospector {

Expand Down Expand Up @@ -121,17 +122,21 @@ public boolean hasCreatorAnnotation(Annotated a) {

@Override
public PropertyName findNameForSerialization(Annotated a) {
return findRosettaGetterName(a)
.or(() -> findRosettaPropertyName(a))
.or(() -> Optional.ofNullable(super.findNameForSerialization(a)))
return getFirstNonEmpty(
() -> findRosettaGetterName(a),
() -> findRosettaPropertyName(a),
() -> Optional.ofNullable(super.findNameForSerialization(a))
)
.orElse(null);
}

@Override
public PropertyName findNameForDeserialization(Annotated a) {
return findRosettaSetterName(a)
.or(() -> findRosettaPropertyName(a))
.or(() -> Optional.ofNullable(super.findNameForDeserialization(a)))
return getFirstNonEmpty(
() -> findRosettaSetterName(a),
() -> findRosettaPropertyName(a),
() -> Optional.ofNullable(super.findNameForDeserialization(a))
)
.orElse(null);
}

Expand Down Expand Up @@ -211,4 +216,14 @@ private Annotated getAnnotatedTypeFromAnnotatedMethod(AnnotatedMethod a) {
);
}
}

private <T> Optional<T> getFirstNonEmpty(Supplier<Optional<T>>... suppliers) {
for (Supplier<Optional<T>> supplier : suppliers) {
Optional<T> maybeValue = supplier.get();
if (maybeValue.isPresent()) {
return maybeValue;
}
}
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.Test;
Expand All @@ -24,6 +25,6 @@ public void itMapsObject() {
assertThat(actual).isEqualTo(expected);

Map<Integer, TestObject> map = getDao().getAllMap();
assertThat(map).containsOnly(Map.entry(1, expected));
assertThat(map).containsAllEntriesOf(Collections.singletonMap(1, expected));
}
}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
<module>RosettaImmutables</module>
</modules>

<properties>
<project.build.releaseJdk>8</project.build.releaseJdk>
<project.build.targetJdk>8</project.build.targetJdk>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down

0 comments on commit 4cfd9bb

Please sign in to comment.