Remove component from Page model json
I have a requirement to remove the Column component and all its child component JSON from page model JSON if it contains a specific property set as "TRUE".
I am trying to check for this property in Column Component Sling Model Exporter and setting the getExportedItems as null. Still, it does not remove the component and its child from the page model JSON.
package com.colorful.core.models;
import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ContainerExporter;
import com.adobe.cq.export.json.ExporterConstants;
import lombok.Getter;
import lombok.NonNull;
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.injectorspecific.ValueMapValue;
import java.util.Collections;
import java.util.Map;
import static com.colorful.core.models.ColumnComponentExporter.RESOURCE_TYPE;
@Model(adaptables = SlingHttpServletRequest.class,
resourceType = RESOURCE_TYPE,
adapters = {ColumnComponentExporter.class, ContainerExporter.class},
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class ColumnComponentExporter implements ContainerExporter {
protected static final String RESOURCE_TYPE = "colorful/components/column";
@ValueMapValue(name = "exportThisComponent")
private boolean exportThisComponent;
@NonNull
public String getExportedType() {
return RESOURCE_TYPE;
}
public Map<String, ? extends ComponentExporter> getExportedItems() {
if (!exportThisComponent) {
return Collections.emptyMap();
}
return null;
}
@NonNull
public String[] getExportedItemsOrder() {
return new String[0];
}
}
How can I remove this column component and its child from page model JSON?
@debal_das @arunpatidar @santoshsai