Skip to content

Commit 47b9952

Browse files
authored
FMWK-467 Issue using refs with yaml file (#161)
Null Pointer Exception using refs with the YAML file
1 parent 954fac9 commit 47b9952

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

src/main/java/com/aerospike/mapper/tools/configuration/ClassConfig.java

+27-17
Original file line numberDiff line numberDiff line change
@@ -183,34 +183,42 @@ public Builder withNamespace(String namespace) {
183183
this.classConfig.setNamespace(namespace);
184184
return this;
185185
}
186+
186187
public Builder withShortName(String shortName) {
187188
this.classConfig.setShortName(shortName);
188189
return this;
189190
}
191+
190192
public Builder withSet(String setName) {
191193
this.classConfig.setSet(setName);
192194
return this;
193195
}
196+
194197
public Builder withTtl(int ttl) {
195198
this.classConfig.setTtl(ttl);
196199
return this;
197200
}
201+
198202
public Builder withVersion(int version) {
199203
this.classConfig.setVersion(version);
200204
return this;
201205
}
206+
202207
public Builder withSendKey(boolean sendKey) {
203208
this.classConfig.setSendKey(sendKey);
204209
return this;
205210
}
211+
206212
public Builder withMapAll(boolean mapAll) {
207213
this.classConfig.setMapAll(mapAll);
208214
return this;
209215
}
216+
210217
public Builder withDurableDelete(boolean durableDelete) {
211218
this.classConfig.setDurableDelete(durableDelete);
212219
return this;
213220
}
221+
214222
public Builder withShortName(boolean sendKey) {
215223
this.classConfig.setSendKey(sendKey);
216224
return this;
@@ -221,7 +229,7 @@ public Builder withFactoryClassAndMethod(@NotNull Class<?> factoryClass, @NotNul
221229
this.classConfig.setFactoryMethod(factoryMethod);
222230
return this;
223231
}
224-
232+
225233
public Builder withKeyField(String fieldName) {
226234
if (this.classConfig.getKey() == null) {
227235
this.classConfig.setKey(new KeyConfig());
@@ -230,7 +238,7 @@ public Builder withKeyField(String fieldName) {
230238
this.classConfig.getKey().setField(fieldName);
231239
return this;
232240
}
233-
241+
234242
public Builder withKeyFieldAndStoreAsBin(String fieldName, boolean storeAsBin) {
235243
if (this.classConfig.getKey() == null) {
236244
this.classConfig.setKey(new KeyConfig());
@@ -240,7 +248,7 @@ public Builder withKeyFieldAndStoreAsBin(String fieldName, boolean storeAsBin) {
240248
this.classConfig.getKey().setStoreAsBin(storeAsBin);
241249
return this;
242250
}
243-
251+
244252
public Builder withKeyGetterAndSetterOf(String getterName, String setterName) {
245253
if (this.classConfig.getKey() == null) {
246254
this.classConfig.setKey(new KeyConfig());
@@ -250,12 +258,12 @@ public Builder withKeyGetterAndSetterOf(String getterName, String setterName) {
250258
this.classConfig.getKey().setSetter(setterName);
251259
return this;
252260
}
253-
261+
254262
public AeroBinConfig withFieldNamed(String fieldName) {
255263
validateFieldExists(fieldName);
256264
return new AeroBinConfig(this, fieldName);
257265
}
258-
266+
259267
private void mergeBinConfig(BinConfig config) {
260268
List<BinConfig> bins = this.classConfig.getBins();
261269
for (BinConfig thisBin : bins) {
@@ -271,46 +279,48 @@ public ClassConfig build() {
271279
return this.classConfig;
272280
}
273281
}
274-
282+
275283
public static class AeroBinConfig {
276284
private final Builder builder;
277285
private final BinConfig binConfig;
278-
286+
279287
public AeroBinConfig(Builder builder, String fieldName) {
280288
super();
281289
this.builder = builder;
282290
this.binConfig = new BinConfig();
283291
this.binConfig.setField(fieldName);
284292
}
285-
293+
286294
public Builder mappingToBin(String name) {
287295
this.binConfig.setName(name);
288296
return this.end();
289297
}
290-
298+
291299
public Builder beingReferencedBy(AerospikeReference.ReferenceType type) {
292-
this.binConfig.setReference(new ReferenceConfig(type, false));
300+
this.binConfig.setReference(new ReferenceConfig(type, false, true));
293301
return this.end();
294302
}
295-
303+
296304
public Builder beingLazilyReferencedBy(AerospikeReference.ReferenceType type) {
297-
this.binConfig.setReference(new ReferenceConfig(type, true));
305+
this.binConfig.setReference(new ReferenceConfig(type, true, true));
298306
return this.end();
299307
}
300-
308+
301309
public Builder beingEmbeddedAs(AerospikeEmbed.EmbedType type) {
302310
EmbedConfig embedConfig = new EmbedConfig();
303311
embedConfig.setType(type);
304312
this.binConfig.setEmbed(embedConfig);
305313
return this.end();
306314
}
315+
307316
public Builder beingEmbeddedAs(AerospikeEmbed.EmbedType type, AerospikeEmbed.EmbedType elementType) {
308317
EmbedConfig embedConfig = new EmbedConfig();
309318
embedConfig.setType(type);
310319
embedConfig.setElementType(elementType);
311320
this.binConfig.setEmbed(embedConfig);
312321
return this.end();
313322
}
323+
314324
public Builder beingEmbeddedAs(AerospikeEmbed.EmbedType type, AerospikeEmbed.EmbedType elementType, boolean saveKey) {
315325
EmbedConfig embedConfig = new EmbedConfig();
316326
embedConfig.setType(type);
@@ -319,6 +329,7 @@ public Builder beingEmbeddedAs(AerospikeEmbed.EmbedType type, AerospikeEmbed.Emb
319329
this.binConfig.setEmbed(embedConfig);
320330
return this.end();
321331
}
332+
322333
/**
323334
* Exclude the field. An excluded field doesn't need any other config, so return the parent.
324335
* This allows for more natural syntax like:
@@ -327,17 +338,16 @@ public Builder beingEmbeddedAs(AerospikeEmbed.EmbedType type, AerospikeEmbed.Emb
327338
* .withFieldName("ignoreMe").beingExcluded()
328339
* .end()
329340
* </code>
330-
* @return
341+
* @return Parent builder
331342
*/
332343
public Builder beingExcluded() {
333344
this.binConfig.setExclude(true);
334345
return this.end();
335346
}
336-
347+
337348
private Builder end() {
338349
this.builder.mergeBinConfig(binConfig);
339350
return this.builder;
340351
}
341352
}
342-
343-
}
353+
}

src/main/java/com/aerospike/mapper/tools/configuration/ReferenceConfig.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ public class ReferenceConfig {
77
private Boolean lazy;
88
private Boolean batchLoad;
99

10-
public ReferenceConfig() {}
11-
public ReferenceConfig(ReferenceType type, boolean lazy) {
10+
public ReferenceConfig() {
11+
}
12+
13+
public ReferenceConfig(ReferenceType type, boolean lazy, boolean batchLoad) {
1214
this.type = type;
1315
this.lazy = lazy;
16+
this.batchLoad = batchLoad;
1417
}
15-
18+
1619
public ReferenceType getType() {
1720
return type;
1821
}

src/main/java/com/aerospike/mapper/tools/utils/TypeUtils.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ private static TypeMapper getMapper(Class<?> clazz, AnnotatedType type, IBaseAer
229229
} else {
230230
// Reference
231231
ReferenceConfig ref = binConfig.getReference();
232-
typeMapper = new ObjectReferenceMapper(ClassCache.getInstance().loadClass(clazz, mapper), ref.getLazy(), ref.getBatchLoad(), ref.getType(), mapper);
232+
typeMapper = new ObjectReferenceMapper(
233+
ClassCache.getInstance().loadClass(clazz, mapper),
234+
ref.getLazy() == null ? false : ref.getLazy(),
235+
ref.getBatchLoad() == null ? true : ref.getBatchLoad(),
236+
ref.getType(), mapper);
233237
addToMap = false;
234238
}
235239
} else {

0 commit comments

Comments
 (0)