Hi Cristian,
Yes, that is possible, however it depends on how you create the typed variable value. There are different options for different uses:
1) object values
The code
String someJsonString = "{...JSON...}";
ObjectValue typedCustomerValue = Variables.serializedObjectValue(someJsonString).serializationDataFormat("application/json").create();
variables.put("customer", typedCustomerValue );
creates an object value. That means, whenever you access the deserialized value (as in the expression), the engine tries to deserialize the value to a java object. In this case, this would fail since we haven't specified a Java type name. The correct code would be
String someJsonString = "{...JSON...}";
ObjectValue typedCustomerValue = Variables.serializedObjectValue(someJsonString).serializationDataFormat("application/json").objectTypeName("com.example.Customer").create();
variables.put("customer", typedCustomerValue );
Then, the expression ${S(customer)...} makes no sense, because customer is already deserialized as an instance of Customer, so you would rather write ${customer.someMethod()...}.
Serializing json as an object value is useful when you need a strongly-typed Java representation.
2) string values
You can submit variables as String values
variables.put("customer", "{Json ... }");
and use them in expressions like ${S(customer)...}.
3) spin values
This is the option discussed in the blogpost you have linked. You have to create the variable like
String someJsonString = "{...JSON...}";
JsonValue typedCustomerValue = org.camunda.spin.plugin.variable.SpinValues.jsonValue(someJsonString).serializationDataFormat("application/json").create();
variables.put("customer", typedCustomerValue );
This tells the engine to use a different serializer (in contrast to option 1) that does not deserialize the variable to a user-specified Java object but to a Spin wrapper object. Then you can use ${ customer.prop("age")... } in the expression.
All of these options make use of Spin, but at different points and for different purposes. Options 2 and 3 are quite similar but 3 saves you the need to create the Spin wrapper yourself by writing S(..) in your expression.
The last option is not yet covered by the user guide and we have a ticket for that ;)
I hope that clarifies the options a little more.
Cheers,
Thorben