This is the metadata schema that we have linked to a keyword

@SemanticEntity(entityName = "HotelMeta", vocabulary = SDL_CORE)
public class HotelKeyword extends KeywordModel {
        private List<KeywordModel> nearbyHotels;

"name": { "$type": "KeywordModelData", "Id": "5228", "Description": "Hotel F", "Key": "FAR", "TaxonomyId": "124", "Title": "Hotel F", "SchemaId": "10872", "Metadata": { "nearbyHotel": { "$type": "KeywordModelData[]", "$values": [ { "Id": "624", "Description": "Rad Keni", "Key": "GBKE", "TaxonomyId": "124", "Title": "Rad Keni", "Metadata": {} }, { "Id": "620", "Description": "Rd Man", "Key": "rd man", "TaxonomyId": "124", "Title": "Rd Man", "Metadata": {} } ] } } },

But when metadata is not informed we've got an Exception

"name": { "$type": "KeywordModelData", "Id": "620", "Description": "Rad Man", "Key": "rad man", "TaxonomyId": "124", "Title": "Rad Man", "Metadata": {} }


java.lang.IllegalArgumentException: Can not set com.dxa.modules.entities.hotel.HotelKeyword field com.dxa.modules.entities.hotel.Hotel.name to com.sdl.webapp.common.api.model.KeywordModel

                at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
                at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
                at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
                at java.lang.reflect.Field.set(Field.java:764)
                at com.sdl.webapp.common.impl.mapping.SemanticMapperImpl$1.doWith(SemanticMapperImpl.java:144)
                at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:693)
                at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:673)
                at com.sdl.webapp.common.impl.mapping.SemanticMapperImpl.createEntity(SemanticMapperImpl.java:105)
                at com.sdl.dxa.tridion.mapping.impl.DefaultModelBuilder.createViewModel(DefaultModelBuilder.java:157)
                at com.sdl.dxa.tridion.mapping.impl.DefaultModelBuilder.buildEntityModel(DefaultModelBuilder.java:123)
                at com.sdl.dxa.tridion.mapping.impl.ModelBuilderPipelineImpl.createEntityModel(ModelBuilderPipelineImpl.java:86)
                at com.dxa.modules.entities.EntityLoader.loadEntityModel(EntityLoader.java:64)
                at com.dxa.modules.entities.EntityLoader.loadPageModelEntity(EntityLoader.java:59)
                at com.dxa.modules.entities.AnotherEntitiesIT.should_load_hotel_from_static_page(AnotherEntitiesIT.java:34)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:498)
                at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
                at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
                at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
                at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
                at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
                at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
                at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
                at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
                at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
                at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
                at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
                at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
                at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
                at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
                at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
                at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
                at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
                at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
                at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
                at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
                at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
                at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
                at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
                at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
                at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

13:20:04.714 [Thread-1] INFO  o.s.w.c.s.GenericWebApplicationContext - Closing org.springframework.web.context.support.GenericWebApplicationContext@482cd91f: startup date [Fri Jul 13 13:19:40 CEST 2018]; root of context hierarchy

UPDATE This error happens not only in our tests but also when running the web app

This is java Entity Class Hotel which has HotelKeyword attribute with name “name”

@SemanticEntity(entityName = "Hotel", vocabulary = SDL_CORE)
public class Hotel extends AbstractEntityModel {

    private Text text;
    private ContactInfo contactInfo;

    private String tripAdvisorCode;
    private HotelKeyword name;
    private Tag brand;
    private Tag city;
    private Tag state;

In line 144 of the log, it's trying to map the information of the attribute name of the hotel entity, but it fails to do so because it expects a field in the metadata called nearby, this happens only when the keyword doesn’t have this metadata field

  • Looking at the Stack Trace, it seems this exception occurred while running a unit test. Do you observe the same problem in the web application? Commented Jul 13, 2018 at 13:57

1 Answer 1


The exception happens on line 144 in this file: https://github.com/sdl/dxa-web-application-java/blob/release/2.0/dxa-framework/dxa-common-api/src/main/java/com/sdl/webapp/common/impl/mapping/SemanticMapperImpl.java

I’m trying to make sense out of the exception message, but I don’t understand it. Apparently, it tries to set a field named name, which your View Model Type (HotelKeyword) doesn’t have. Not sure why it thinks it should set that property. And what is type com.dxa.entities.hotel.Hotel ?

Note that there’s trace output happening (e.g. line 137). Maybe a log file with log level set to TRACE can shed some light?


With the additional information provided, the exception message starts making sense to me: it just says that it is unable to set your Hotel.name property to an object of type KeywordModel, which makes sense, because the property is more strongly typed than that (it's of type HotelKeyword).

I guess this happens in that scenario, because there is no Schema ID in the R2 Data Model, so it can't use Semantic Mapping to determine a specific View Model Type to use and hence instantiates a generic KeywordModel.

This is indeed defective, because it could/should have determined the View Model Type from your Hotel.name property type.

Does this problem occur in general, or only for dynamically expanded Keyword Models?

As a work-around, would it be possible to make the Hotel.name property more loosely typed (let its type be KeywordModel), so that you don't hit this exception. If all is well, it will still instantiate a HotelKeyword in case a Schema ID (and metadata) is present. In case it is not present, you won't have any additional metadata to map anyways, so a generic KeywordModel should be sufficient.

  • I added more comments. We think we found a new bug in the product.
    – tfinez
    Commented Jul 17, 2018 at 8:55
  • Ah, now I get it. I have updated my answer. Seems like bug, indeed, but hopefully with a work-around possible. Commented Jul 17, 2018 at 11:06
  • I don't get it. It's not that the Hotel.name is empty, but when it fails is when Hotel.name.nearbyHotels is empty.
    – tfinez
    Commented Jul 17, 2018 at 14:51
  • Based on the R2 JSON you provided, it seems that in the problematic scenario, the CM Keyword doesn’t have metadata (nor a metadata Schema) at all. As a result, there is no Schema ID in the JSON and as a result of that, the semantic mapping logic gets confused and instantiates KeywordModel instead of HotelKeyword. Commented Jul 18, 2018 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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