registerParser
public <V> xapi.util.api.RemovalHandler registerParser(Class<V> classLit,
xapi.util.api.ConvertsValue<V,String> serializer,
xapi.util.api.ConvertsValue<String,V> deserializer)
Registers a de/serializer for a given class literal,
and returns a removal method to undo the registration.
The ONLY safe way to use the undo method is to
a) synchronize(classLit) {
b) RemovalHandler r = registerParser(...);
try {
// do stuff, but don't try to acquire a lock.
// just send your request and get out.
} finally {
r.remove();// resets the given de/serializer combo.
}
Do not keep references of the removal handler beyond the method that
called registerParser, unless you are willing to risk indeterminism.
We will do check-and-set,
Also, for code to work in gwt or other transpiled targets,
you MUST be using a class literal, and not a class _REFERENCE_.
registerParser(IPojo.class, ...) - Good!
Class theClass = IPojo.class;
registerParser(theClass, ...) - Bad!
When you use class literals, the reference can be reliably resolved,
otherwise it's on you to record every method passing that class lit along,
and do something filthy, like stash it in a ThreadLocal<Stack>,.
The deal for magically generated code is "pass in the interface you want,
get back the best (or only) implementation for your platform.
- Specified by:
registerParser in interface IOService
- Parameters:
classLit - - The type to register serializers for.
serializer - - ConvertsValue
deserializer - - ConvertsValue
- Returns:
- - A removal method to undo registration;
using this in a try / finally block, in case you just
want to borrow the de/serialization process.