Skip to content

Add typed getter for session #320

@gdaniel

Description

@gdaniel

Session is implemented as a Map<Object, Object>, so we have a single way to access session values: session.get(key), which returns an Object.

Most of the time we know what we are storing in the session though, and we have to cast the result of get:

String myString = (String) context.getSession().get("myKey");

While this is fine for simple types it is annoying for complex ones, especially when accessed in transitions where we typically want a compact syntax:

myState.body(...)
    .next()
    .when(((MyComplexType)context.getSession().get("myKey")).getX() == 2).moveTo(...)

This could be simplified by implementing typed getters for the session:

myState.body(...)
    .next()
    .when(context.getSession().get("myKey", MyComplexType.class).getX() == 2).moveTo(...)

Additional getters could be provided for basic types: getAsString, getAsInt, etc

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions