Skip to content

Commit d112a5e

Browse files
committed
Enrich entity with part while iterating json file
1 parent b40753e commit d112a5e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/main/java/com/rapiddweller/benerator/composite/PartModifier.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.rapiddweller.benerator.factory.BeneratorExceptionFactory;
77
import com.rapiddweller.benerator.wrapper.ProductWrapper;
88
import com.rapiddweller.common.ArrayUtil;
9+
import com.rapiddweller.model.data.ComplexTypeDescriptor;
910
import com.rapiddweller.model.data.Entity;
1011

1112
import java.util.Collection;
@@ -58,9 +59,12 @@ public boolean execute(BeneratorContext context) {
5859
ProductWrapper<?> wrapper = context.getCurrentProduct();
5960
if (wrapper != null) {
6061
Object part = ((Entity) wrapper.unwrap()).getComponent(partName);
61-
if (part != null) {
62-
applyToPart(part, context);
62+
// Init part and add into currentProduct
63+
if (part == null) {
64+
part = new Entity((ComplexTypeDescriptor) null, null);
65+
((Entity)context.getCurrentProduct().unwrap()).setComponent(partName, part);
6366
}
67+
applyToPart(part, context);
6468
}
6569
return true;
6670
}

src/main/java/com/rapiddweller/model/data/Entity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ public Entity(String name, DescriptorProvider descriptorProvider, Object... comp
6767
public Entity(ComplexTypeDescriptor descriptor, Object... componentKeyValuePairs) {
6868
this.descriptor = descriptor;
6969
this.components = BeneratorFactory.getInstance().createComponentMap();
70-
for (int i = 0; i < componentKeyValuePairs.length; i += 2) {
71-
setComponent((String) componentKeyValuePairs[i], componentKeyValuePairs[i + 1]);
70+
if (componentKeyValuePairs != null) {
71+
for (int i = 0; i < componentKeyValuePairs.length; i += 2) {
72+
setComponent((String) componentKeyValuePairs[i], componentKeyValuePairs[i + 1]);
73+
}
7274
}
7375
}
7476

0 commit comments

Comments
 (0)