2

I want to access Structure Group metadata in my DXA 2.2 java page models. Following the DXA documentation I have added the InheritMetadataPageModelBuilder model builder to the pipeline in my Page Rendering TBB. When previewing the page, I see that Structure Group metadata is present in the page JSON. I also see following additional json field.

"ExtensionData": {
    "Schemas": {
      "$type": "RichTextData[]",
      "$values": [
        {
          "Fragments": [
            "313729"
          ]
        }
      ]
    }
  }

However, on the on my DXA application side, I get the following runtime error when I access a page:

java.lang.ClassCastException: com.sdl.dxa.api.datamodel.model.RichTextData cannot be cast to java.lang.String
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
    at com.sdl.dxa.tridion.mapping.impl.DefaultModelBuilder.getInheritedSemanticSchemas(DefaultModelBuilder.java:168)

It seems DefaultModelBuilder is not able to parse 'ExtensionData' element of the PageModelData. It is clearly expecting String object instead of RichTextData. ExtensionData is something added by InheritMetadataPageModelBuilder itself, so I have no control over it.

Did I miss something or is it's a DXA bug?

Any ideas to fix it?

4
  • @Sahid, I'm trying to reproduce this issue in OOTB DXA 2.2, for me, the ExtensionData type value getting string instead of RichTextData. look at this GetTypedArrayOfValues code logic github.com/sdl/dxa-content-management/blob/…, for me getting the schema as List<string>, which is expected. I don't understand how it's for you to get RichTextData. can you explain how is your SG metadata schema looks and how it's configured on your current published page. – Velmurugan Mar 21 at 9:14
  • @Velmurugan, it is indeed very strange that ExtensionData has a list of RichTextData in my case. As the class InheritMetadataPageModelBuilder explicitly creates a list<string> for the schema ids. Let me further dig into this... – Shahid Eqamuddin Mar 22 at 18:26
  • @Velmurugan, I found out the reason of the issue, please check my answer. – Shahid Eqamuddin Mar 25 at 8:17
  • Good to know, you can accept your answer – Velmurugan Mar 27 at 6:51
3

It turns out that CMS side of DXA 2.2 for SDL Web 8.5 has a bug (or incompatibility with Java DXA 2.2 side) which is causing values of Schemas to be generated as a List<RichTextData> instead of List<String> in the ExtensionData of the JSON page model.

As in our case, InheritMetadataPageModelBuilderi is using the method GetTypedArrayOfValues which doesn't have this following vital line which is responsible for creating a List<String> for Schema Ids.

if (strings.Count == fieldValues.Count) return strings.ToArray();

(For example, this version of method: GetTypedArrayOfValues doesn't have this statement.)

Later releases for DXA CMS have already fixed this issue and it is delivered with the 9.x CMS versions. As Velu also pointed out he is seeing the expected behaviour.

For those who happen to use 8.5 CMS with DXA 2.2 version, this issue can be addressed by a simple fix (just adding a missing statement, as stated above). Or perhaps a fix-release is already available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.