@@ -321,6 +321,10 @@ public int size() {
321321 // TODO: test remove
322322 @ Override
323323 public Set <Entry <String , Object >> entrySet () {
324+ return entrySet (true );
325+ }
326+
327+ public Set <Entry <String , Object >> entrySet (boolean shouldComputeValue ) {
324328 return new AbstractSet <>() {
325329 @ Override
326330 public Iterator <Entry <String , Object >> iterator () {
@@ -335,7 +339,7 @@ public boolean hasNext() {
335339 @ Override
336340 public Entry <String , Object > next () {
337341 Map .Entry <String , Type > mapEntry = mapIterator .next ();
338- return new LazyEntry (mapEntry .getKey (), mapEntry .getValue ());
342+ return new LazyEntry (mapEntry .getKey (), mapEntry .getValue (), shouldComputeValue );
339343 }
340344
341345 @ Override
@@ -421,11 +425,15 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
421425
422426 private class LazyEntry implements Entry <String , Object > {
423427 private final String key ;
428+ private final Type type ;
429+ private final boolean shouldComputeValue ;
424430 private Object cachedValue ;
425431 private boolean valueComputed = false ;
426432
427- LazyEntry (String key , Type type ) {
433+ LazyEntry (String key , Type type , boolean shouldComputeValue ) {
428434 this .key = key ;
435+ this .type = type ;
436+ this .shouldComputeValue = shouldComputeValue ;
429437 }
430438
431439 @ Override
@@ -435,8 +443,14 @@ public String getKey() {
435443
436444 @ Override
437445 public Object getValue () {
438- if (valueComputed == false ) {
439- cachedValue = ESONObject .this .get (key ); // Use the object's get method to handle modifications
446+ if (shouldComputeValue && valueComputed == false ) {
447+ if (type == null ) {
448+ cachedValue = null ;
449+ } else if (type instanceof Mutation mutation ) {
450+ cachedValue = mutation .object ();
451+ } else {
452+ cachedValue = convertTypeToValue (type );
453+ }
440454 valueComputed = true ;
441455 }
442456 return cachedValue ;
@@ -445,7 +459,9 @@ public Object getValue() {
445459 @ Override
446460 public Object setValue (Object value ) {
447461 Object oldValue = ESONObject .this .put (key , value );
448- cachedValue = value ;
462+ if (shouldComputeValue ) {
463+ cachedValue = value ;
464+ }
449465 return oldValue ;
450466 }
451467
@@ -492,6 +508,18 @@ public ESONArray(List<Type> elements, Supplier<Values> arrayValues) {
492508 this .arrayValues = arrayValues ;
493509 }
494510
511+ public Supplier <Values > arrayValues () {
512+ return arrayValues ;
513+ }
514+
515+ public Iterator <?> iterator (boolean shouldMaterialize ) {
516+ if (shouldMaterialize ) {
517+ return super .iterator ();
518+ } else {
519+ return elements .iterator ();
520+ }
521+ }
522+
495523 @ Override
496524 public Object get (int index ) {
497525 Type type = elements .get (index );
0 commit comments