Maybe the application architecture can be improved to avoid this
situation altogether? Because you have a TemplateModel instead of a
plain object, yet you know its exact class (SimpleSequence), so it's
not because it comes from a template, and that's why it's already a
TemplateModel.

Anyway, if you have to do that, there are a few approaches:

1. Copying: DeepUnwrap.unwrap can give you back a "plain" object of
your TemplateModel. Though in case it's a TemplateSequenceModel, it
will create a deep copy into a List, so just for searching it's not
efficient. However, SimpleSequence.toList() often did the same too.

2. Adapting: Assuming Configuraton.getObjectWrapper()
(Environment.getObjectWrapper()) is instanceof BeansWrapper (in almost
all applications it is), use ((BeansWrapper)
objectWrapper).unwrap(model, List.class). This doesn't copy, it
creates an adapter.

3. Just use the TemplateModel interfaces directly, and iterate through
the sequence with that. Templates do that too, so if you want to be
close to template behavior, that's the way to go.


On Wed, Jun 12, 2024 at 4:22 PM Ingo Mahnke <ingo.mah...@quvion.org> wrote:
>
> Hallo!! As is see "toList()” in SimpleSequence is marked as deprecated.
> I have so search (no change of data) within my SimpleSequence. So how I can 
> access the underlying list in a future proof way?
>
> THANK YOU
> Ingo
>
>



--
Best regards,
Daniel Dekany

Reply via email to