Why is an excerpt projection not applied automatically for a Spring Data REST item resource?

后端 未结 2 1381
广开言路
广开言路 2020-12-03 05:36

I made a projection which should expose nested entities:

@Projection(name = \"inlineBusiness\", types = { UserModel.class })
public interface InlineBusinessU         


        
2条回答
  •  情话喂你
    2020-12-03 05:39

    I'm not going to argue with @Oliver Drotbohm, as this is indeed the correct answer, however, if you want a cheeky workaround, just define a getter for the entity field with a slightly different name (using the OP's example):

    BusinessModel getBusinessInline() { return this.businessModel; }
    

    Will result in a JSON payload of:

    {
        .
        .
        "businessInline": {"name":"stuff etc"}
        .
        .
    }
    

    Presuming your consuming service will accept that, then its an option.

    Not big or clever, but it works.

提交回复
热议问题