I am working with a DXA 2.0 Java implementation where I have created 2 custom models, one for a schema and the second one for an embedded schema
Below is the code
This is for Entity 1
@SemanticEntity(entityName = "Entity1", vocabulary = SDL_CORE, public_ = true)
@Data
@EqualsAndHashCode(callSuper = true)
public class Entity1 extends AbstractEntityModel{
@JsonProperty("ContentItems")
@SemanticProperty("contentItems")
public List<Entity2> contentItems;
@JsonProperty("Items")
@SemanticProperty("items")
public List<Paragraph> items;
@JsonProperty("SomeText")
@SemanticProperty("someText")
public String someText;
}
This is for Entity 2
@Data
@EqualsAndHashCode(callSuper = true)
public class Entity2 extends AbstractEntityModel {
@JsonProperty("Key")
private String key;
@JsonProperty("TextValue")
private RichText textValue;
@JsonProperty("MultimediaValue")
private MediaItem multimediaValue;
}
Note that Entity1 was created referring the default Article class and Entity2 was created referring the default Paragraph class.
I also have a controller that renders these entities on a view. And for tracing I have a System.out.println
statement which prints out the entity object. The code for which is mentioned below
@RequestMapping(method = RequestMethod.GET, value = {"/Entity1/{entityId}"})
public ModelAndView Entity1Display(HttpServletRequest request, @PathVariable String entityId) {
EntityModel entity = (EntityModel) request.getAttribute("_entity_");
System.out.println(entity);
ModelAndView m = new ModelAndView();
m.setViewName("/ModuleName/Entity/ViewName");
return m;
}
The System.out.println
statement displays this
Entity1(contentItems=[Entity2(key=null, textValue=null, multimediaValue=null), Entity2(key=null, textValue=null, multimediaValue=null)], items=[Paragraph(subheading=Something Paragraph, content=Something, media=null, caption=null), Paragraph(subheading=Something Paragraph 2, content=22222, media=null, caption=null)], someText=Test123)
Where you see that Entity1 is mapped correctly and gets data except for the Entity2 data which is null even though there is content in it on the CM.
So what seems to be wrong here with the Entity2 model? Should these models be in a specific package? I guess the package might not be an issue since Entity1 gets its data. I think it might be an issue with the embedded schema and I might have missed a step here while creating the embedded schema.
Edit:
These are the thing I have tried but it still doesn't work
-Having semantic entity at entity 2 as well
@SemanticEntity(entityName = "Entity2", vocabulary = SDL_CORE, public_ = true)
@Data
@EqualsAndHashCode(callSuper = true)
public class Entity2 extends AbstractEntityModel {
@JsonProperty("Key")
@SemanticProperty("key")
private String key;
@JsonProperty("TextValue")
@SemanticProperty("textValue")
private RichText textValue;
@JsonProperty("MultimediaValue")
@SemanticProperty("multimediaValue")
private MediaItem multimediaValue;
}
-Tried SCHEMA_ORG instead of SDL_CORE in vocabulary
My Component source looks like this
<Entity1 xmlns="uuid:8bbc604b-26fc-46d8-855d-bc16fb54ef0a">
<contentItems>
<key>Test1FW</key>
<textValue>TestFW</textValue>
</contentItems>
<contentItems>
<key>Test2FW</key>
<textValue>TestFW</textValue>
</contentItems>
<items>
<subheading>Something Paragraph</subheading>
<content>Something</content>
</items>
<items>
<subheading>Something Paragraph 2</subheading>
<content>22222</content>
</items>
<someText>Test123</someText>
</Entity1>
@SemanticEntity
, right. Indeed, theEntity2
class should have such an annotation referring to to root element/type name of the embedded schema (unless that happens to be the same as the class name).