Invalid reference while parsing enum type from XML

102 views
Skip to first unread message

Alexander Eckert

unread,
Oct 19, 2016, 8:29:57 AM10/19/16
to XStream User
Hi,

I try to parse a XML with XStream 1.4.9 generated by an older version. I checked the changes, found the commit and the faq entry for immutable type references.

The type I try to parse is an enum. I tried calling addImmutableType(EnumType.class, true) on the XStream object but to no avail. The parser still claims that the type is not referenceable as the check is answered by EnumMapper.

Is there any way to enable reading references for enum types?

Greetings
Alex

Jörg Schaible

unread,
Oct 19, 2016, 2:07:01 PM10/19/16
to xstrea...@googlegroups.com
Hi Alex,

Alexander Eckert wrote:

> Hi,
>
> I try to parse a XML with XStream 1.4.9 generated by an older version.

What means 'old' here? The last change to EnumMapper.isImmutableType was for
XStream 1.3 resp. 8 years ago...

> I checked the changes, found the commit and the faq entry for immutable
> type references.
>
> The type I try to parse is an enum. I tried calling
> addImmutableType(EnumType.class, true) on the XStream object but to no
> avail. The parser still claims that the type is not referenceable as the
> check is answered by EnumMapper.
>
> Is there any way to enable reading references for enum types?

The only possibility I see is by installing a custom mapper:

==================== %< =============
XStream xstream = new XStream() {
protected MapperWrapper wrapMapper(MapperWrapper next) {
return new MapperWrapper(next) {
@Override
public boolean isImmutableValueType(Class type) {
return (YourEnum.class.isAssignableFrom(type)) ||
super.isImmutableValueType(type);
}
};
}
}
==================== %< =============

Cheers,
Jörg

Jörg Schaible

unread,
Oct 19, 2016, 2:36:18 PM10/19/16
to xstrea...@googlegroups.com
OK, correction, the implementation of the inner function must have been
something along:

==================== %< =============
if (YourEnum.class.isAssignableFrom(type))
return false;
return super.isImmutableValueType(type);
==================== %< =============

;-)

Alexander Eckert

unread,
Oct 20, 2016, 4:10:36 AM10/20/16
to XStream User, joerg.s...@gmx.de
Well old means ancient :-). The Files where generated with 1.1.3.

Installing a custom mapper worked. I just use isReferenceable instead of isImmutableValueType.

Thanks,
Alex

Jörg Schaible

unread,
Oct 20, 2016, 6:40:28 AM10/20/16
to xstrea...@googlegroups.com
Hi Alex,

Alexander Eckert wrote:

> Well old means ancient :-). The Files where generated with 1.1.3.

:-D

> Installing a custom mapper worked. I just use isReferenceable instead of
> isImmutableValueType.

Even better.

Cheers,
Jörg

Reply all
Reply to author
Forward
0 new messages