@@ -1029,22 +1029,27 @@ private static void flattenArray(ESONArray arr, String arrayFieldName, List<KeyE
10291029 } else {
10301030 int elementCount = 0 ;
10311031 for (Type type : arr .arrEntry .mutationArray ) {
1032- if (type instanceof Mutation mutation ) {
1033- // This is a mutated element - create new FieldEntry with mutation
1034- flatKeyArray .add (new FieldEntry (null , mutation ));
1035- elementCount ++;
1036- } else if (type instanceof ESONObject nestedObj ) {
1037- // Nested object - flatten recursively
1038- flattenObject (nestedObj , null , flatKeyArray );
1039- elementCount ++;
1040- } else if (type instanceof ESONArray nestedArr ) {
1041- // Nested array - flatten recursively
1042- flattenArray (nestedArr , null , flatKeyArray );
1043- elementCount ++;
1044- } else {
1045- // Regular type (FixedValue, VariableValue, NullValue) - create field entry
1046- flatKeyArray .add (new FieldEntry (null , type ));
1047- elementCount ++;
1032+ switch (type ) {
1033+ case Mutation mutation -> {
1034+ // This is a mutated element - create new FieldEntry with mutation
1035+ flatKeyArray .add (new FieldEntry (null , mutation ));
1036+ elementCount ++;
1037+ }
1038+ case ESONObject nestedObj -> {
1039+ // Nested object - flatten recursively
1040+ flattenObject (nestedObj , null , flatKeyArray );
1041+ elementCount ++;
1042+ }
1043+ case ESONArray nestedArr -> {
1044+ // Nested array - flatten recursively
1045+ flattenArray (nestedArr , null , flatKeyArray );
1046+ elementCount ++;
1047+ }
1048+ case null , default -> {
1049+ // Regular type (FixedValue, VariableValue, NullValue) - create field entry
1050+ flatKeyArray .add (new FieldEntry (null , type ));
1051+ elementCount ++;
1052+ }
10481053 }
10491054 }
10501055
@@ -1059,7 +1064,7 @@ public void writeToStream(ESONObject object, StreamOutput out) throws IOExceptio
10591064 out .writeByte ((byte ) 'N' );
10601065 // TODO: How to write size
10611066 // TODO: Assert flattened or support transition to flattened
1062- for (KeyEntry entry : object .getKeyArray ()) {
1067+ for (KeyEntry entry : object .getKeyArray ()) {
10631068 if (entry instanceof ObjectEntry ) {
10641069
10651070 } else if (entry instanceof ArrayEntry ) {
@@ -1069,6 +1074,5 @@ public void writeToStream(ESONObject object, StreamOutput out) throws IOExceptio
10691074 }
10701075 entry .writeTo (out );
10711076 }
1072-
10731077 }
10741078}
0 commit comments