IllegalArgumentException: Multi-value array must not contain maps/objects | Community
Skip to main content
New Participant
August 18, 2022
Solved

IllegalArgumentException: Multi-value array must not contain maps/objects

  • August 18, 2022
  • 1 reply
  • 1929 views

Hello again!

 

Getting this error when I run the test class below at ctx.load().json line. It seems that I can't create an array of objects in the json mock... Is there another way that I could implement the json?

 

package com.test.core.models.impl.section; import io.wcm.testing.mock.aem.junit5.AemContext; import io.wcm.testing.mock.aem.junit5.AemContextExtension; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @ExtendWith({AemContextExtension.class, MockitoExtension.class}) public class ATest { private final AemContext ctx = new AemContext(); private A a; @BeforeEach public void setUp() throws Exception { ctx.addModelsForClasses(A.class); ctx.load().json("/com/test/core/models/impl/section/ATest.json", "/content"); a = ctx.resourceResolver().getResource("/content/a") .adaptTo(A.class); } @2785667 void testGetCards() { assertEquals("title", a.getCards().get(0).getTitle()); assertEquals("description", a.getCards().get(1).getDescription()); assertEquals("image", a.getCards().get(2).getFileReference()); assertTrue( a.getCards().size()==1); } }

 

The ATest.json mock

{ "a": { "jcr:primaryType": "nt:unstructured", "sling:resourceType": "test/components/a", "cards": [{ "title":"title", "description":"description", "fileReference":"image" }] } }

 

The models

public class A { protected static final String RESOURCE_TYPE = "test/components/a"; @ChildResource private List<ACard> cards; } public class ACard implements Card { @ValueMapValue private String title; @ValueMapValue private String description; @ValueMapValue private String fileReference; }

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by rute

Done!

{
  "a": {
    "jcr:primaryType": "nt:unstructured",
    "sling:resourceType": "consorcio/components/a",
    "cards": {
      "jcr:primaryType": "nt:unstructured",
      "item0": {
        "title": "Title",
        "description": "description",
        "fileReference":"image"
      }
    }
  }
}

1 reply

ruteAuthorAccepted solution
New Participant
August 18, 2022

Done!

{
  "a": {
    "jcr:primaryType": "nt:unstructured",
    "sling:resourceType": "consorcio/components/a",
    "cards": {
      "jcr:primaryType": "nt:unstructured",
      "item0": {
        "title": "Title",
        "description": "description",
        "fileReference":"image"
      }
    }
  }
}