[Simple-support] cannot use @Convert with @Attributes!?...
Brought to you by:
niallg
|
From: -=}\\*/{=- <rui...@gm...> - 2011-12-13 00:37:10
|
Exception in thread "main" org.simpleframework.xml.core.AttributeException:
Cannot use @org.simpleframework.xml.Attribute(name=, empty=, required=true)
to represent field 'match' java.util.regex.Pattern abc.kis.Url.match
at
org.simpleframework.xml.core.AttributeLabel.getConverter(AttributeLabel.java:110)
at org.simpleframework.xml.core.CacheLabel.getConverter(CacheLabel.java:312)
at org.simpleframework.xml.core.Composite.readVariable(Composite.java:666)
at org.simpleframework.xml.core.Composite.readInstance(Composite.java:635)
class Url {
@Attribute
Pattern match;
@Attribute
String target;
}
<url match=".*/" target="index.html"/>
i'm using a RegistryStrategy with a PatternConverter that works fine with
@Element...
<url target="index.html">
<match>.*/</match>
</url>
... but that match belongs to an attribute not an element...
i though of converting the Url class instead... or make a pattern wrapper,
but rather get the pattern working as an @Attribute, since i'll need it
several times and seams more correct.
the converter below:
public class PatternConverter extends SimpleConverter<Pattern> {
public static Registry bind(Registry r) {
return bind(r, Pattern.class, PatternConverter.class);
}
@Override
public Pattern read(InputNode in) throws Exception {
return Pattern.compile(in.getValue());
}
@Override
public void write(OutputNode on, Pattern p) {
on.setValue(p.toString());
}
}
|