How can I serialize java.util.concurrent.TimeUnit with the Simple XML lib (version 2.6.5 / 2.6.6)?
Here’s my class I want to serialize:
@Root(name="settings")
public class Config
{
// some more code
@Element(name="timeunit", required=true)
private static final TimeUnit timeunit = TimeUnit.SECONDS;
// some more code
}
Using Simple:
File f = // ...
Config cfg = new Config();
Serializer ser = new Persister();
ser.write(cfg, f);
And I’m getting this Exception:
org.simpleframework.xml.transform.TransformException: Transform of class java.util.concurrent.TimeUnit$4 not supported
I tested other Annotations like @Default so far, but same problem. Wondering why Simple has a problem with TimeUnits – all other Types (Classes / primitive Types) work without any problem.
Here’s a possible solution:
Annotation:
Converter: