diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/dynamic/DynamicTypeBuilder.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/dynamic/DynamicTypeBuilder.java index 0eb04b0bdba..cf6f7a9e9ce 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/dynamic/DynamicTypeBuilder.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/dynamic/DynamicTypeBuilder.java @@ -41,6 +41,7 @@ import org.eclipse.persistence.mappings.OneToOneMapping; import org.eclipse.persistence.mappings.converters.EnumTypeConverter; import org.eclipse.persistence.mappings.foundation.AbstractDirectMapping; +import org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping; import org.eclipse.persistence.platform.database.DatabasePlatform; import org.eclipse.persistence.platform.xml.XMLParser; import org.eclipse.persistence.platform.xml.XMLPlatformFactory; @@ -214,6 +215,9 @@ private boolean requiresInitialization(DatabaseMapping mapping) { if (mapping.isDirectToFieldMapping() && mapping.getAttributeClassification() != null && mapping.getAttributeClassification().isPrimitive()) { return true; } + if (mapping.isCollectionMapping()) { + return true; + } if (mapping.isForeignReferenceMapping()) { ForeignReferenceMapping frMapping = (ForeignReferenceMapping) mapping; return frMapping.usesIndirection() || frMapping.isCollectionMapping(); diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/dynamic/DynamicPropertiesInitializatonPolicy.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/dynamic/DynamicPropertiesInitializatonPolicy.java index bacad70fb0e..7abc3664cd8 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/dynamic/DynamicPropertiesInitializatonPolicy.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/dynamic/DynamicPropertiesInitializatonPolicy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -78,6 +78,9 @@ else if (primClass == ClassConstants.PBYTE) { value = Byte.MIN_VALUE; } } + else if (mapping.isCollectionMapping()) { + value = mapping.getContainerPolicy().containerInstance(); + } else if (mapping.isForeignReferenceMapping()) { ForeignReferenceMapping refMapping = (ForeignReferenceMapping)mapping; if (refMapping.usesIndirection() && diff --git a/moxy/org.eclipse.persistence.moxy/src/test/java/org/eclipse/persistence/testing/jaxb/dynamic/DynamicJAXBCollectionTestCases.java b/moxy/org.eclipse.persistence.moxy/src/test/java/org/eclipse/persistence/testing/jaxb/dynamic/DynamicJAXBCollectionTestCases.java index 257507a6e57..4612d58ad0a 100644 --- a/moxy/org.eclipse.persistence.moxy/src/test/java/org/eclipse/persistence/testing/jaxb/dynamic/DynamicJAXBCollectionTestCases.java +++ b/moxy/org.eclipse.persistence.moxy/src/test/java/org/eclipse/persistence/testing/jaxb/dynamic/DynamicJAXBCollectionTestCases.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Set; import java.util.Vector; +import java.util.ArrayList; import jakarta.xml.bind.JAXBElement; import jakarta.xml.bind.Marshaller; @@ -33,6 +34,7 @@ import org.eclipse.persistence.jaxb.JAXBContextProperties; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory; +import org.eclipse.persistence.oxm.NamespaceResolver; import org.eclipse.persistence.testing.jaxb.dynamic.util.MyList; import org.w3c.dom.Document; @@ -65,6 +67,23 @@ public void testXSDSingleListUnmarshal() throws Exception { assertEquals("Incorrect phoneNumber type.", "work", firstPhoneNumber.get("type")); } + public void testXSDInstantiateList() throws Exception { + InputStream schemaStream = ClassLoader.getSystemResourceAsStream(XSD_SINGLE); + jaxbContext = DynamicJAXBContextFactory.createContextFromXSD(schemaStream, null, null, null); + + var customer = jaxbContext.newDynamicEntity("Customer"); + + assertNotNull(customer.get("phoneNumbers")); + + var resolver = new NamespaceResolver(); + resolver.setDefaultNamespaceURI("www.example.org/customer"); + + var phoneNumbers = jaxbContext.getValueByXPath(customer, "phone-numbers", resolver, Object.class); + + assertNotNull(phoneNumbers); + assertEquals(ArrayList.class, phoneNumbers.getClass()); + } + public void testXSDMultipleListUnmarshal() throws Exception { InputStream schemaStream = ClassLoader.getSystemResourceAsStream(XSD_MULTI); jaxbContext = DynamicJAXBContextFactory.createContextFromXSD(schemaStream, null, null, null);