|
Joerg Schaible made changes - 05/Dec/06 07:19 AM
Sure, of course I'd use that if I could. The problem, as noted above, is that I want to alias certain fields as attributes. You'll notice that unless a single value converter is used, you can't get a field to map to an attribute. See reply to comment on close.
Stephan Morais made changes - 06/Dec/06 07:03 PM
Maybe I'm reading this wrong, but here's what I see in AttributeMapper: protected SingleValueConverter getLocalConverterFromItemType(Class type) { I suppose another workaround to this would be to also allow normal Converters in this case. Can you elaborate a bit more about your special use case? We had until now no need for the UnmarshallingContext in a SIngleValueConverter, since those converters are typically used to convert a dedicated type, so there's no need for providing this info again. Apart from this information, no call to any other method in the UnmarshallingContext is even valid within the context of a SingleValueConverter. Since the value of an attribute has to be a single string, the AttributeMapper is restricted to use SingleValueConverter only. I may have stumbled across a need for this feature as well. In my case, I would like to map a simple Java 5+ enum as an attribute. As per an email with Joerg, currently, I must create a specific SingleValueConverter(SVC) for my enum for this to work. Below is a SVC that illustrates this: class SingleValueEnumConverter extends AbstractSingleValueConverter { private final Class enumType; public SingleValueEnumConverter(Class type) { this.enumType = type; } public boolean canConvert(Class c) { return c.equals(enumType); } public Object fromString(String value) {
return Enum.valueOf(enumType, value);
} This will work, but It would be nice to have a generic SingleValueEnumConverter that could take advantage of the UnmarshallingContext if it were provided to the SVC. It is not as simple as it might look. Context.getRequiredType() will return the type of the current XML element ... but not the type of the attribute. Therefore providing the context will not help to solve this. Enums have now attribute support. Therefore this issue lacks again of a valid use case.
Joerg Schaible made changes - 11/Feb/08 06:01 PM
Closed after no further comment has been given.
Joerg Schaible made changes - 25/Feb/08 04:53 PM
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Hi Stephan,
please use a normal Converter implementation. The SingleValueConverter is meant for simple types with a single string representation - nothing more.