7

My SocialMediaButtons class has a List of type SocialMediaButton (Embedded Schema).

Unless I add Semantic Property markup the buttons variable becomes null.

Before adding Semantic Markup

public class SocialMediaButtons extends AbstractEntityModel {
    private String fieldTest;
    private List<SocialMediaButton> buttons;

    public List<SocialMediaButton> getButtons() {
        return buttons;
    }

    public void setButtons(List<SocialMediaButton> buttons) {
        this.buttons = buttons;
    }

    public String getFieldTest() {
        return fieldTest;
    }

    public void setFieldTest(String fieldTest) {
        this.fieldTest = fieldTest;
    }
}

Result when using the SocialMediaButtons class without markup:

Result when using the SocialMediaButtons class without markup

Note how fieldTest does resolve correctly.

After adding Semantic Markup

Entityname is the same name as the Class name:

@SemanticEntity(entityName = "SocialMediaButtons", vocabulary = SDL_CORE, prefix = "smbs")
public class SocialMediaButtons extends AbstractEntityModel {
    @SemanticProperty("smbs:fieldTest")
    private String fieldTest;

    @SemanticProperty("smbs:buttons")
    private List<SocialMediaButton> buttons;

    public List<SocialMediaButton> getButtons() {
        return buttons;
    }

    public void setButtons(List<SocialMediaButton> buttons) {
        this.buttons = buttons;
    }

    public String getFieldTest() {
        return fieldTest;
    }

    public void setFieldTest(String fieldTest) {
        this.fieldTest = fieldTest;
    }
}

Now both resolve correctly:

enter image description here

Is this intended behaviour? (since entity name and class name are essentially the same here).

Also confused that I need to put markup on SocialMediaButtons to make it work but not on SocialMediaButton.

6

I think the problem is in the field name; the implicit mapping assumes that when a List-type property name is plural (e.g. buttons), the associated field name in CM is singular (e.g. button).

It seems that in your case the CM field name is also plural and that is why you need an explicit mapping.

  • This does indeed seem to be the case. Was this a decision based on how XML is structured? Really unexpected answer since I thought it had to do with the embedded object. On a side note: when we used buttonss the variable name in CM had to be buttons. Isn't this a problem for consistency with different languages? (Let's say we used 'knoppen' for our variable name instead of buttons). – CodeFinity Oct 25 '16 at 9:03
  • Indeed, this was designed this way because it's common to let CM field names of multi-value fields be singular because it's used as XML element name for each value. But, admittedly, it is also causing quite some confusion and the "depluralization" algorithm doesn't even work properly for all nouns in English: it's simply stripping the trailing s if any. – Rick Pannekoek Oct 25 '16 at 16:59

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.