@@ -1068,10 +1068,14 @@ def java_serializer(self, data_type):
1068
1068
return self .fmt ('%s.INSTANCE' , serializer_class )
1069
1069
else :
1070
1070
serializers_class = JavaClass ('com.dropbox.core.stone.StoneSerializers' )
1071
- if is_nullable_type (data_type ):
1071
+ if is_nullable_type (data_type ) and is_struct_type (data_type .data_type ):
1072
+ return self .fmt ('%s.nullableStruct(%s)' ,
1073
+ serializers_class , self .java_serializer (data_type .data_type ))
1074
+ elif is_nullable_type (data_type ):
1072
1075
return self .fmt ('%s.nullable(%s)' ,
1073
1076
serializers_class , self .java_serializer (data_type .data_type ))
1074
1077
elif is_list_type (data_type ):
1078
+ # TODO: also support passing collapsed to list serializer
1075
1079
return self .fmt ('%s.list(%s)' ,
1076
1080
serializers_class , self .java_serializer (data_type .data_type ))
1077
1081
else :
@@ -3889,7 +3893,7 @@ def generate_union_serialize(self, data_type):
3889
3893
w .out ('writeTag("%s", g);' , field .name )
3890
3894
serializer = w .java_serializer (field .data_type )
3891
3895
value = 'value.%s' % j .param_name (field )
3892
- if j .is_collapsible (field .data_type ):
3896
+ if j .is_collapsible (field .data_type ) or is_nullable_type ( field . data_type ) and j . is_collapsible ( field . data_type . data_type ) :
3893
3897
w .out ('%s.serialize(%s, g, true);' , serializer , value )
3894
3898
else :
3895
3899
w .out ('g.writeFieldName("%s");' , field .name )
@@ -3940,7 +3944,7 @@ def generate_union_deserialize(self, data_type):
3940
3944
w .out ('%s fieldValue = null;' , j .java_class (field_dt , boxed = True , generics = True ))
3941
3945
with w .conditional_block (is_nullable_type (field .data_type ), 'if (p.getCurrentToken() != JsonToken.END_OBJECT)' ):
3942
3946
field_serializer = w .java_serializer (field_dt )
3943
- if j .is_collapsible (field_dt ):
3947
+ if j .is_collapsible (field_dt ) or is_nullable_type ( field_dt ) and j . is_collapsible ( field_dt . data_type ) :
3944
3948
w .out ('fieldValue = %s.deserialize(p, true);' , field_serializer )
3945
3949
else :
3946
3950
w .out ('expectField("%s", p);' , field .name )
0 commit comments