Option to exclude allowedComponents list in sling model exporter | Community
Skip to main content
Level 2
February 3, 2025

Option to exclude allowedComponents list in sling model exporter

  • February 3, 2025
  • 3 replies
  • 967 views

Hi Team,

 

We have requirement to remove all the allowedComponent list from the page sling exporter, there are more than 50+ custom SPA components due to that model.json size is larger. In 6.5 version, is there any way to ignore allowedComponents ?

 

Thanks for the help in advance!!

3 replies

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
February 4, 2025

Hi, 

You need to annotate the propery with @JsonIgnore and this will be ignored. Please check this; https://experienceleague.adobe.com/en/docs/experience-manager-learn/foundation/development/develop-sling-model-exporter#applying-jackson-annotations 

 

Hope this helps

Esteban Bustamante
Level 2
February 4, 2025

Thanks for responding, but getExportedAllowedComponents() is inside ResponsiveGrid.class, need to overlay the responsiveGrid class, not sure if that is best approach here. pls suggest.

Level 2
February 19, 2025

Hi @sai_krishna_1404 You can overlay the class and use Lombok delegate feature to do that to ensure any update in future doesn't impact the functionality.

refer to this: http://experience-aem.blogspot.com/2023/04/aem-cloud-service-delegate-annotation-extend-core-component-sling-models.html


Hi @chaudharynick , Thanks for the response!

Tried using Lombok delegate feature, where ever we are calling resourceType:{"wcm/foundation/components/responsivegrid"}, want this below code to be executed but it is not working. Let me know if any issue with the code.

import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import com.day.cq.wcm.foundation.model.responsivegrid.export.ResponsiveGridExporter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.experimental.Delegate;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Via;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.via.ResourceSuperType;

@Model(
adaptables = {SlingHttpServletRequest.class},
adapters = {ComponentExporter.class},
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL,
resourceType = {"wcm/foundation/components/responsivegrid"}
)
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class ResponsiveGridDelegate implements ResponsiveGridExporter {

@Self
@Via(type = ResourceSuperType.class)
@Delegate(excludes = DelegationExclusion.class)
private ResponsiveGridExporter delegate;

@Override
@JsonIgnore
@JsonProperty("allowedComponents")
public com.day.cq.wcm.foundation.model.export.AllowedComponentsExporter getExportedAllowedComponents() {
return null;
}

private interface DelegationExclusion {
com.day.cq.wcm.foundation.model.export.AllowedComponentsExporter getExportedAllowedComponents();
}
}

Shiv_Prakash_Patel
Community Advisor
Community Advisor
February 4, 2025

@sai_krishna_1404 ,

Modify the Sling Model JSON export by using Jackson annotations as below:

1. Use the @JsonIgnore annotation to exclude allowedComponents

@Inject @JsonIgnore // Exclude allowedComponents from model.json private List<AllowedComponent> allowedComponents;

2. If modifying the model is not an option, you can exclude specific properties globally via OSGi configurations. 

Navigate to http://localhost:4502/system/console/configMgr, find com.adobe.cq.wcm.core.components.internal.models.v1.PageImpl, and remove allowedComponents from the exported properties list.

Regards,

Shiv Prakash
Level 2
February 4, 2025

Hi Shiv, Thanks for responding!
On your second approach, I don't see config for "com.adobe.cq.wcm.core.components.internal.models.v1.PageImpl" to exclude allowedComponents, is it part of Core Component version (https://experienceleague.adobe.com/en/docs/experience-manager-core-components/using/versions) ? I updated core version to 2.23.4, is it a custom config that need to be enabled & add exclusionList in the config, pls suggest!

kautuk_sahni
Community Manager
Community Manager
February 18, 2025

@sai_krishna_1404 Did you find the suggestions helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!

Kautuk Sahni