2
2
3
3
import codes .laivy .serializable .Allocator ;
4
4
import codes .laivy .serializable .Serializer ;
5
- import codes .laivy .serializable .annotations .UseEmptyConstructor ;
6
5
import codes .laivy .serializable .config .Config ;
7
6
import codes .laivy .serializable .context .ArrayContext ;
8
7
import codes .laivy .serializable .context .Context ;
9
8
import codes .laivy .serializable .context .MapContext ;
10
9
import codes .laivy .serializable .context .PrimitiveContext ;
11
10
import codes .laivy .serializable .exception .IncompatibleReferenceException ;
11
+ import codes .laivy .serializable .exception .NullConcreteClassException ;
12
12
import codes .laivy .serializable .factory .instance .InstanceFactory ;
13
13
import codes .laivy .serializable .utilities .Classes ;
14
14
import org .jetbrains .annotations .NotNull ;
@@ -42,7 +42,7 @@ public final class NativeContextFactory implements ContextFactory {
42
42
int length = Array .getLength (object );
43
43
44
44
for (int index = 0 ; index < length ; index ++) {
45
- context .write (serializer .serialize (Array .get (object , index ), config ));
45
+ context .write (serializer .serialize (Array .get (object , index )));
46
46
}
47
47
48
48
return context ;
@@ -124,10 +124,6 @@ public final class NativeContextFactory implements ContextFactory {
124
124
@ NotNull InstanceFactory instanceFactory = config .getInstanceFactory ();
125
125
@ Nullable Father father = config .getFather ();
126
126
127
- if (reference .isAnnotationPresent (UseEmptyConstructor .class )) {
128
- instanceFactory = InstanceFactory .constructor ();
129
- }
130
-
131
127
// Serialize
132
128
@ NotNull Object instance = instanceFactory .generate (reference );
133
129
@@ -140,7 +136,10 @@ public final class NativeContextFactory implements ContextFactory {
140
136
@ Nullable Field field = fields .getOrDefault (name , null );
141
137
142
138
if (field == null ) {
143
- throw new InvalidClassException ("there's no field with name '" + name + "'" );
139
+ throw new IncompatibleReferenceException ("there's no field with name '" + name + "' at class '" + reference .getName () + "'" );
140
+ } else if (object .getContext (name ).isNullContext ()) {
141
+ // Set outer field instance
142
+ Allocator .setFieldValue (field , instance , null );
144
143
} else {
145
144
config = Config .create (serializer , Father .create (field , instance ));
146
145
@@ -156,16 +155,20 @@ public final class NativeContextFactory implements ContextFactory {
156
155
} else {
157
156
@ NotNull Class <?>[] references = Classes .getReferences (field );
158
157
158
+ if (references .length == 0 ) {
159
+ throw new NullConcreteClassException ("there's no concrete references for field '" + field + "'" );
160
+ }
161
+
159
162
for (@ NotNull Class <?> fieldReference : references ) try {
160
163
// Set normal field instance
161
- @ Nullable Object value = object .getObject (fieldReference , name );
164
+ @ Nullable Object value = object .getObject (fieldReference , name , Config . create ( serializer , Father . create ( field , instance )) );
162
165
Allocator .setFieldValue (field , instance , value );
163
166
164
167
continue fields ;
165
168
} catch (@ NotNull IncompatibleReferenceException ignore ) {
166
169
}
167
170
168
- throw new IncompatibleReferenceException ("cannot deserialize field '" + field + "' because there's no compatible and concrete references for it: " + Arrays .toString (references ));
171
+ throw new IncompatibleReferenceException ("cannot deserialize field '" + field + "' because there's no compatible references for it: " + Arrays .toString (references ));
169
172
}
170
173
}
171
174
}
0 commit comments