Skip to content

Throw SQLFeatureNotSupportedException when we encounter unexpected data instead of throwing AssertionError #112

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 1 commit into from
Jul 17, 2025
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 @@ -101,8 +101,8 @@ public EmbeddableMappingType getEmbeddableMappingType() {
}

/**
* We replaced this method with {@link #createBsonValue(Object, WrapperOptions)} to make it clear that
* {@link #createJdbcValue(Object, WrapperOptions)} is not called by Hibernate ORM.
* We replaced this method with {@link #createBsonValue(Object, WrapperOptions)}, to make it clear that this method
* is not called by Hibernate ORM.
*/
@Override
public BsonValue createJdbcValue(@Nullable Object domainValue, WrapperOptions options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,7 @@ static Object toDomainValue(BsonValue value, Class<?> domainType) throws SQLFeat
} else if (value instanceof BsonDecimal128 v) {
return toDomainValue(v);
} else if (value instanceof BsonString v) {
if (domainType.isArray()) {
return toDomainValue(v);
} else {
return toDomainValue(v, domainType);
}
return toDomainValue(v, domainType);
} else if (value instanceof BsonBinary v) {
return toDomainValue(v);
} else if (value instanceof BsonObjectId v) {
Expand Down Expand Up @@ -251,17 +247,25 @@ private static BigDecimal toDomainValue(BsonDecimal128 value) {
return value.decimal128Value().bigDecimalValue();
}

public static String toStringDomainValue(BsonValue value) {
public static String toStringDomainValue(BsonValue value) throws SQLFeatureNotSupportedException {
return toDomainValue(value.asString(), String.class);
}

private static <T> T toDomainValue(BsonString value, Class<T> domainType) {
var v = value.getValue();
private static <T> T toDomainValue(BsonString value, Class<T> domainType) throws SQLFeatureNotSupportedException {
Object result;
if (domainType.equals(Character.class)) {
result = toDomainValue(v);
if (domainType.equals(char[].class)) {
result = toDomainValue(value);
} else {
result = v;
var v = value.getValue();
if (domainType.equals(Character.class) && v.length() == 1) {
result = toDomainValue(v);
} else if (domainType.equals(String.class) || domainType.equals(Object.class)) {
result = v;
} else {
throw new SQLFeatureNotSupportedException(format(
"Value [%s] of type [%s] is not supported for the domain type [%s]",
value, value.getClass().getTypeName(), domainType));
}
}
return domainType.cast(result);
}
Expand Down Expand Up @@ -306,7 +310,7 @@ private static Object toDomainValue(BsonArray value, Class<?> elementType) throw
}

/** @see #toBsonValue(char[]) */
private static char[] toDomainValue(BsonString value) {
private static char[] toDomainValue(BsonString value) throws SQLFeatureNotSupportedException {
return toDomainValue(value, String.class).toCharArray();
}
}