Skip to content

Commit e47c76c

Browse files
committed
Add unit tests for from_json()/to_json() with nested arrays. (#242, #248)
1 parent 327bc7f commit e47c76c

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

metafix/src/test/java/org/metafacture/metafix/MetafixMethodTest.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,42 @@ public void shouldConvertArrayFromJson() {
11391139
);
11401140
}
11411141

1142+
@Test
1143+
public void shouldConvertNestedArrayFromJson() {
1144+
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
1145+
"from_json(test)"
1146+
),
1147+
i -> {
1148+
i.startRecord("1");
1149+
i.literal("test", "{\"zoo[]\":[{\"animals[]\":[[\"ant\",\"dog\"],\"cat\",[\"fish\",[\"zebra\",\"horse\"],\"hippo\"],\"giraffe\"]}]}");
1150+
i.endRecord();
1151+
},
1152+
(o, f) -> {
1153+
o.get().startRecord("1");
1154+
o.get().startEntity("test");
1155+
o.get().startEntity("zoo[]");
1156+
o.get().startEntity("1");
1157+
o.get().startEntity("animals[]");
1158+
o.get().startEntity("1[]");
1159+
o.get().literal("1", "ant");
1160+
o.get().literal("2", "dog");
1161+
o.get().endEntity();
1162+
o.get().literal("2", "cat");
1163+
o.get().startEntity("3[]");
1164+
o.get().literal("1", "fish");
1165+
o.get().startEntity("2[]");
1166+
o.get().literal("1", "zebra");
1167+
o.get().literal("2", "horse");
1168+
o.get().endEntity();
1169+
o.get().literal("3", "hippo");
1170+
o.get().endEntity();
1171+
o.get().literal("4", "giraffe");
1172+
f.apply(4).endEntity();
1173+
o.get().endRecord();
1174+
}
1175+
);
1176+
}
1177+
11421178
@Test
11431179
public void shouldConvertHashFromJson() {
11441180
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
@@ -3308,6 +3344,45 @@ public void shouldConvertArrayToJson() {
33083344
);
33093345
}
33103346

3347+
@Test
3348+
public void shouldConvertNestedArrayToJson() {
3349+
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
3350+
"to_json(test)"
3351+
),
3352+
i -> {
3353+
i.startRecord("1");
3354+
i.startEntity("test");
3355+
i.startEntity("zoo[]");
3356+
i.startEntity("1");
3357+
i.startEntity("animals[]");
3358+
i.startEntity("1[]");
3359+
i.literal("1", "ant");
3360+
i.literal("2", "dog");
3361+
i.endEntity();
3362+
i.literal("2", "cat");
3363+
i.startEntity("3[]");
3364+
i.literal("1", "fish");
3365+
i.startEntity("2[]");
3366+
i.literal("1", "zebra");
3367+
i.literal("2", "horse");
3368+
i.endEntity();
3369+
i.literal("3", "hippo");
3370+
i.endEntity();
3371+
i.literal("4", "giraffe");
3372+
i.endEntity();
3373+
i.endEntity();
3374+
i.endEntity();
3375+
i.endEntity();
3376+
i.endRecord();
3377+
},
3378+
o -> {
3379+
o.get().startRecord("1");
3380+
o.get().literal("test", "{\"zoo[]\":[{\"animals[]\":[[\"ant\",\"dog\"],\"cat\",[\"fish\",[\"zebra\",\"horse\"],\"hippo\"],\"giraffe\"]}]}");
3381+
o.get().endRecord();
3382+
}
3383+
);
3384+
}
3385+
33113386
@Test
33123387
public void shouldConvertHashToJson() {
33133388
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(

0 commit comments

Comments
 (0)