Skip to content

Commit df0cb25

Browse files
committed
fix the WrappedUUIDJavaType UUID as string/char test
1 parent 1822f68 commit df0cb25

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/main/java/it/aboutbits/springboot/toolbox/persistence/javatype/base/WrappedUUIDJavaType.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,15 @@ public <X> T wrap(X value, WrapperOptions wrapperOptions) {
6969
if (clazz.isInstance(value)) {
7070
return (T) value;
7171
}
72-
if (value instanceof UUID uuidValue) {
73-
return constructor.newInstance(uuidValue);
74-
}
7572

76-
throw unknownWrap(value.getClass());
73+
return switch (value) {
74+
case UUID uuidValue -> constructor.newInstance(uuidValue);
75+
case String uuidStringValue -> constructor.newInstance(UUID.fromString(uuidStringValue));
76+
case byte[] uuidBytesValue -> constructor.newInstance(UUID.fromString(new String(
77+
uuidBytesValue,
78+
StandardCharsets.UTF_8
79+
)));
80+
default -> throw unknownWrap(value.getClass());
81+
};
7782
}
7883
}

src/test/java/it/aboutbits/springboot/toolbox/persistence/javatype/impl/jpa/WrapperTypesModel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import lombok.Setter;
6666
import org.hibernate.annotations.JavaType;
6767
import org.hibernate.annotations.JdbcType;
68+
import org.hibernate.type.descriptor.jdbc.CharJdbcType;
6869
import org.hibernate.type.descriptor.jdbc.UUIDJdbcType;
6970

7071
@Entity
@@ -132,7 +133,7 @@ public class WrapperTypesModel implements Identified<WrapperTypesModel.ID> {
132133

133134
@SuppressWarnings("JpaAttributeTypeInspection")
134135
@JavaType(WrapUUIDRecordJavaType.class)
135-
@JdbcType(UUIDJdbcType.class)
136+
@JdbcType(CharJdbcType.class)
136137
private WrapUUIDRecord uuidValueAsString;
137138

138139
@SuppressWarnings("JpaAttributeTypeInspection")
@@ -190,7 +191,7 @@ public class WrapperTypesModel implements Identified<WrapperTypesModel.ID> {
190191

191192
@SuppressWarnings("JpaAttributeTypeInspection")
192193
@JavaType(WrapUUIDClassJavaType.class)
193-
@JdbcType(UUIDJdbcType.class)
194+
@JdbcType(CharJdbcType.class)
194195
private WrapUUIDClass uuidValueClassAsString;
195196

196197
public record ID(

src/test/resources/db/changelog/2024-09-06-create-wrapper-type-testing-table.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ databaseChangeLog:
5454
type: uuid
5555
- column:
5656
name: uuid_value_as_string
57-
type: uuid
57+
type: char(36)
5858
- column:
5959
name: big_decimal_value_class
6060
type: double
@@ -96,4 +96,4 @@ databaseChangeLog:
9696
type: uuid
9797
- column:
9898
name: uuid_value_class_as_string
99-
type: uuid
99+
type: char(36)

0 commit comments

Comments
 (0)