Skip to content

Commit be1624b

Browse files
committed
add copy constructors to custom type for jpa implicit dto projection
1 parent f8cb6ed commit be1624b

5 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/main/java/it/aboutbits/springboot/toolbox/type/EmailAddress.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public EmailAddress(@Nullable String value) {
2626
this.value = value.toLowerCase();
2727
}
2828

29+
@SuppressWarnings("unused")
30+
EmailAddress(EmailAddress other) {
31+
this(other.value);
32+
}
33+
2934
@Override
3035
public String toString() {
3136
return value;

src/main/java/it/aboutbits/springboot/toolbox/type/Iban.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public Iban(@Nullable String value) {
2222
this.value = value.toUpperCase();
2323
}
2424

25+
@SuppressWarnings("unused")
26+
Iban(Iban other) {
27+
this(other.value);
28+
}
29+
2530
@Override
2631
public String toString() {
2732
return value;

src/main/java/it/aboutbits/springboot/toolbox/type/ScaledBigDecimal.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public record ScaledBigDecimal(
2323
public static final ScaledBigDecimal TWO = new ScaledBigDecimal(2);
2424
public static final ScaledBigDecimal TEN = new ScaledBigDecimal(10);
2525

26+
@SuppressWarnings("unused")
27+
ScaledBigDecimal(ScaledBigDecimal other) {
28+
this(other.value);
29+
}
30+
2631
public ScaledBigDecimal(BigDecimal value) {
2732
this.value = value.setScale(MATH_CONTEXT.getPrecision(), MATH_CONTEXT.getRoundingMode());
2833
}

src/test/java/it/aboutbits/springboot/toolbox/type/EmailAddressTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void invalidValues_shouldFail(String value) {
5050
void null_shouldFail() {
5151
//noinspection DataFlowIssue
5252
assertThatIllegalArgumentException().isThrownBy(
53-
() -> new EmailAddress(null)
53+
() -> new EmailAddress((String) null)
5454
);
5555
}
5656
}

src/test/java/it/aboutbits/springboot/toolbox/type/IbanTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void invalidValues_shouldFail(String value) {
5555
void null_shouldFail() {
5656
//noinspection DataFlowIssue
5757
assertThatIllegalArgumentException().isThrownBy(
58-
() -> new Iban(null)
58+
() -> new Iban((String) null)
5959
);
6060
}
6161
}

0 commit comments

Comments
 (0)