TemplateModel @Include Bean Support?

Hi Team,

I am working on a project with a relatively deep domain model that I am wanting to pass down to vaadin flow via a TemplateModel.

Right now, I am having to use a very long @Include, because the domain models have a lot of fields that are irrelevant to the view.
Is there a way I can annotate my bean, rather than having to have long @Include strings on the TemplateModel?

Here’s an example of just one of the elements of the template model - and this is less than half of the properties required to import.

@Include(["id", "name", "date",
                "location.id", "plant.id", "client.id",
                "operationDetails", "operationDetails.id", "operationDetails.startDate", "operationDetails.endDate", "operationDetails.code", "operationDetails.comment", "operationDetails.metersTo", "operationDetails.metersFrom",  "operationDetails.metersRecovered", "operationDetails.recoveryPercentage",
                "operationDetails.code.id", "operationDetails.code.name", "operationDetails.code.code"])
        @Encode(value=LongToStringEncoder.class, path="id")
        @Encode(value=LocalDateToStringEncoder.class, path="date")
        @Encode(value=LongToStringEncoder.class, path="location.id")
        @Encode(value=LongToStringEncoder.class, path="plant.id")
        @Encode(value=LongToStringEncoder.class, path="client.id")
        @Encode(value=LongToStringEncoder.class, path="operationDetails.code.id")
        void setDorList(List<Dor> list)

Thanks,
~Ben

In addition to this, it seems like the built in ObjectMapper is not rendering LocalTime objects either.
… no error - it just doesn’t show up in the JSON.

e.g if I include
@Include([“id”, “name”, “startTime”, “endTime”]
)

Start time and end time do not show in the JSON on the client side. But id and name do.
Note that if I link to a LocalDateTime, I get an error if I don’t specify a serialiser / deserialiser - but with LocalTimes, I get nothing.

I’ve imported jsr310 support into the pom - which works if you manually register the ObjectMapper, but when you are setting objects to the model, you seem to get the default ObjectMapper that is being used with PolymerTemplate?

Is there any way to manually control the ObjectMapper that is used with PolymerTemplate?

OK.

Have just verified this with a simple test.

    class Demo{
        LocalTime sTime
        LocalTime eTime
        String blah
    }
	
	//Inside Template Model
	void setTest(Demo obj)
	
	//Init Code
	Demo e = new Demo(blah: "abc123", sTime: LocalTime.now(), eTime: LocalTime.now())
    getModel().setTest(e)
	
	//Debug output of JSON representation of e (via client side)
	Test: {"blah":"abc123","nodeId":815}

Looks like for some reason the LocalTime property is being omitted.

Even with a forced @Include and custom encoders… the property doesn’t show up on the client side.

        @Include(["blah", "sTime", "eTime"]
)
        @Encode(value=LocalTimeToStringEncoder.class, path="sTime")
        @Encode(value=LocalTimeToStringEncoder.class, path="eTime")

Not sure what’s going on with this. Ended up using the spring object mapper and passing the data in as a JSON string then manually decoding on the client side.