We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Map<Object, Object>
session.get(key)
Object
Most of the time we know what we are storing in the session though, and we have to cast the result of get:
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
getAsString
getAsInt
The text was updated successfully, but these errors were encountered:
See this piece of code:
private static class MyMap<K, V> extends HashMap<K, V> { public String getAsString(K key) { return get(key, String.class); } public Integer getAsInt(K key) { return get(key, Integer.class); } public <T> T get(K key, Class<T> type) { Object o = this.get(key); return (T) o; } }
Sorry, something went wrong.
gdaniel
No branches or pull requests
Session is implemented as a
Map<Object, Object>
, so we have a single way to access session values:session.get(key)
, which returns anObject
.Most of the time we know what we are storing in the session though, and we have to cast the result of
get
: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:
This could be simplified by implementing typed getters for the session:
Additional getters could be provided for basic types:
getAsString
,getAsInt
, etcThe text was updated successfully, but these errors were encountered: