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

Pin the release target to jdk8 #107

Merged
merged 5 commits into from
Jun 13, 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
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