@@ -70,39 +70,10 @@ public static void serializeArray(MappingType elementMappingType, Object[] value
7070		}
7171		for  ( Object  value  : values  ) {
7272			try  {
73- 				if  (value  == null ) {
74- 					writer .nullValue ();
75- 				}
76- 				else  if  ( elementMappingType  instanceof  EmbeddableMappingType  ) {
77- 					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 () );
101- 				}
73+ 				serialize (elementMappingType , value , options , writer );
10274			}
10375			catch  (IOException  e ) {
104- 				// TODO : do better than this 
105- 				throw  new  RuntimeException ( e  );
76+ 				throw  new  IllegalArgumentException ( "Could not serialize JSON array value"  , e  );
10677			}
10778		}
10879		writer .endArray ();
@@ -159,6 +130,42 @@ public static void serialize(EmbeddableMappingType embeddableMappingType,
159130		writer .endObject ();
160131	}
161132
133+ 	private  static  void  serialize (MappingType  mappedType , Object  value , WrapperOptions  options , JsonDocumentWriter  writer )
134+ 			throws  IOException  {
135+ 		if  ( value  == null  ) {
136+ 			writer .nullValue ();
137+ 		}
138+ 		else  if  ( mappedType  instanceof  EmbeddableMappingType  ) {
139+ 			serialize ( (EmbeddableMappingType ) mappedType , value , options , writer  );
140+ 		}
141+ 		else  if  ( mappedType  instanceof  BasicType <?> ) {
142+ 			//noinspection unchecked 
143+ 			final  BasicType <Object > basicType  = (BasicType <Object >) mappedType ;
144+ 
145+ 			if  ( isArrayType (basicType .getJdbcType ())) {
146+ 				final  int  length  = Array .getLength ( value  );
147+ 				writer .startArray ();
148+ 				if  ( length  != 0  ) {
149+ 					//noinspection unchecked 
150+ 					final  JavaType <Object > elementJavaType  = ( (BasicPluralJavaType <Object >) basicType .getJdbcJavaType () ).getElementJavaType ();
151+ 					final  JdbcType  elementJdbcType  = ( (ArrayJdbcType ) basicType .getJdbcType () ).getElementJdbcType ();
152+ 					final  Object  domainArray  = basicType .convertToRelationalValue ( value  );
153+ 					for  ( int  j  = 0 ; j  < length ; j ++ ) {
154+ 						writer .serializeJsonValue (Array .get (domainArray ,j ), elementJavaType , elementJdbcType , options );
155+ 					}
156+ 				}
157+ 				writer .endArray ();
158+ 			}
159+ 			else  {
160+ 				writer .serializeJsonValue (basicType .convertToRelationalValue ( value ),
161+ 						(JavaType <Object >)basicType .getJdbcJavaType (),basicType .getJdbcType (), options );
162+ 			}
163+ 		}
164+ 		else  {
165+ 			throw  new  UnsupportedOperationException ( "Support for mapping type not yet implemented: "  + mappedType .getClass ().getName () );
166+ 		}
167+ 	}
168+ 
162169	/** 
163170	 * JSON object attirbute serialization 
164171	 * @see #serialize(EmbeddableMappingType, Object, WrapperOptions, JsonDocumentWriter) 
@@ -176,40 +183,18 @@ private static void serializeMapping(EmbeddableMappingType embeddableMappingType
176183			if  ( attributeMapping  instanceof  SelectableMapping  ) {
177184				final  String  name  = ( (SelectableMapping ) attributeMapping  ).getSelectableName ();
178185				writer .objectKey ( name  );
179- 				if  (values [i ] == null ) {
180- 					writer .nullValue ();
181- 				}
182- 				else  if  (attributeMapping .getMappedType () instanceof  BasicType <?>) {
183- 					final  BasicType <Object > basicType  = (BasicType <Object >) attributeMapping .getMappedType ();
184- 					if  ( isArrayType (basicType .getJdbcType ())) {
185- 						final  int  length  = Array .getLength ( values [i ] );
186- 						writer .startArray ();
187- 						if  ( length  != 0  ) {
188- 							//noinspection unchecked 
189- 							final  JavaType <Object > elementJavaType  = ( (BasicPluralJavaType <Object >) basicType .getJdbcJavaType () ).getElementJavaType ();
190- 							final  JdbcType  elementJdbcType  = ( (ArrayJdbcType ) basicType .getJdbcType () ).getElementJdbcType ();
191- 							final  Object  domainArray  = basicType .convertToRelationalValue (   values [i ] );
192- 							for  ( int  j  = 0 ; j  < length ; j ++ ) {
193- 								writer .serializeJsonValue (Array .get (domainArray ,j ), elementJavaType , elementJdbcType , options );
194- 							}
195- 						}
196- 						writer .endArray ();
197- 					}
198- 					else  {
199- 						writer .serializeJsonValue (basicType .convertToRelationalValue ( values [i ]),
200- 								(JavaType <Object >)basicType .getJdbcJavaType (),basicType .getJdbcType (), options );
201- 					}
202- 				}
203- 				else  if  ( attributeMapping .getMappedType () instanceof  EmbeddableMappingType  ) {
186+ 
187+ 				if  ( attributeMapping .getMappedType () instanceof  EmbeddableMappingType  ) {
204188					writer .startObject ();
205189					serializeMapping (  (EmbeddableMappingType )attributeMapping .getMappedType (), values [i ], options ,writer );
206190					writer .endObject ();
191+ 				} else  {
192+ 					serialize (attributeMapping .getMappedType (), values [i ], options , writer );
207193				}
208194
209195			}
210196			else  if  ( attributeMapping  instanceof  EmbeddedAttributeMapping  ) {
211197				if  ( values [i ] == null  ) {
212- 					//writer.nullValue(); 
213198					continue ;
214199				}
215200				final  EmbeddableMappingType  mappingType  = (EmbeddableMappingType ) attributeMapping .getMappedType ();
0 commit comments