Skip to content

Commit 57fb0b7

Browse files
committed
HHH-17404 : applied eview comment
1 parent 805763c commit 57fb0b7

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/JsonHelper.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,31 @@ public static void serializeArray(MappingType elementMappingType, Object[] value
7373
if (value == null) {
7474
writer.nullValue();
7575
}
76-
else {
76+
else if ( elementMappingType instanceof EmbeddableMappingType ) {
7777
JsonHelper.serialize( (EmbeddableMappingType) elementMappingType, value, options, writer );
78+
} else if ( elementMappingType instanceof BasicType<?> ) {
79+
//noinspection unchecked
80+
final BasicType<Object> basicType = (BasicType<Object>) elementMappingType;
81+
82+
if ( isArrayType(basicType.getJdbcType())) {
83+
final int length = Array.getLength( value );
84+
if ( length != 0 ) {
85+
//noinspection unchecked
86+
final JavaType<Object> elementJavaType = ( (BasicPluralJavaType<Object>) basicType.getJdbcJavaType() ).getElementJavaType();
87+
final JdbcType elementJdbcType = ( (ArrayJdbcType) basicType.getJdbcType() ).getElementJdbcType();
88+
final Object domainArray = basicType.convertToRelationalValue( value );
89+
for ( int j = 0; j < length; j++ ) {
90+
writer.serializeJsonValue(Array.get(domainArray,j), elementJavaType, elementJdbcType, options);
91+
}
92+
}
93+
}
94+
else {
95+
writer.serializeJsonValue(basicType.convertToRelationalValue( value),
96+
(JavaType<Object>)basicType.getJdbcJavaType(),basicType.getJdbcType(), options);
97+
}
98+
}
99+
else {
100+
throw new UnsupportedOperationException( "Support for mapping type not yet implemented: " + elementMappingType.getClass().getName() );
78101
}
79102
}
80103
catch (IOException e) {

hibernate-core/src/main/java/org/hibernate/type/format/OsonDocumentReader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ public JsonDocumentItemType next() {
100100
currentValue = this.parser.getBytes();
101101
return JsonDocumentItemType.VALUE;
102102
default :
103-
assert false:"Unknown OSON event";
103+
throw new IllegalStateException( "Unknown OSON event: " + evt );
104104
}
105-
return null;
106105
}
107106

108107
@Override

hibernate-core/src/main/java/org/hibernate/type/format/OsonDocumentWriter.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
import java.sql.Time;
2323
import java.sql.Timestamp;
2424
import java.time.Duration;
25-
import java.time.Instant;
2625
import java.time.OffsetDateTime;
27-
import java.time.ZoneOffset;
2826
import java.util.UUID;
2927

3028
/**
@@ -108,7 +106,14 @@ public JsonDocumentWriter stringValue(String value) {
108106

109107
@Override
110108
public JsonDocumentWriter numberValue(Number value) {
111-
this.generator.write((BigDecimal) value );
109+
if (value instanceof BigDecimal) {
110+
this.generator.write((BigDecimal) value );
111+
} else if (value instanceof BigInteger) {
112+
this.generator.write((BigInteger) value );
113+
} else {
114+
//fallback.
115+
this.generator.write( value.longValue() );
116+
}
112117
return this;
113118
}
114119

@@ -214,17 +219,8 @@ private void serializeValue(Object value,
214219
}
215220
break;
216221
case SqlTypes.TIMESTAMP_UTC:
217-
if( value instanceof OffsetDateTime ) {
218-
OffsetDateTime odt = javaType.unwrap( value, OffsetDateTime.class, options );
219-
generator.write( odt );
220-
break;
221-
}
222-
else if (value instanceof Instant ) {
223-
Instant instant = javaType.unwrap( value, Instant.class, options );
224-
generator.write(instant.atOffset( ZoneOffset.UTC ) );
225-
break;
226-
}
227-
generator.write( javaType.unwrap( value,String.class,options ) );
222+
OffsetDateTime odt = javaType.unwrap( value, OffsetDateTime.class, options );
223+
generator.write( odt );
228224
break;
229225
case SqlTypes.NUMERIC:
230226
case SqlTypes.DECIMAL:
@@ -251,8 +247,7 @@ else if (value instanceof Instant ) {
251247
break;
252248
case SqlTypes.ARRAY:
253249
case SqlTypes.JSON_ARRAY:
254-
assert false:"array case should be treated at upper level";
255-
break;
250+
throw new IllegalStateException( "array case should be treated at upper level" );
256251
default:
257252
throw new UnsupportedOperationException( "Unsupported JdbcType nested in JSON: " + jdbcType );
258253
}

0 commit comments

Comments
 (0)