[Simple-support] Problem with deserialization empty XML element into generic field
Brought to you by:
niallg
|
From: Yaroslav N. <yar...@is...> - 2014-01-16 10:42:24
|
Hi!
I have a data model with classes both generic and immutable like in code
snippet below:
package ru.ispras.texterra.core;
import java.io.StringReader;
import java.io.StringWriter;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.core.Persister;
public class SimpleSerializerTestCase {
public static class SomeGeneric<T> {
@Element(name = "value")
private final T value;
public SomeGeneric(@Element(name = "value") T value) {
this.value = value;
}
}
public static class SomeConcrete extends SomeGeneric<String> {
public SomeConcrete(@Element(name = "value") String value) {
super(value);
}
}
public static void main(String[] args) throws Exception {
Persister persister = new Persister();
StringWriter writer = new StringWriter();
persister.write(new SomeConcrete(""), writer);
StringReader reader = new StringReader(writer.toString());
// Exception in thread "main"
org.simpleframework.xml.core.ValueRequiredException: Empty
// value for @org.simpleframework.xml.Element(name=value,
data=false, required=true,
// type=void) on field 'value' private final java.lang.Object
//
ru.ispras.texterra.core.SimpleSerializerTestCase$SomeGeneric.value in class
//
ru.ispras.texterra.core.SimpleSerializerTestCase$SomeConcrete at line 2
SomeConcrete read = persister.read(SomeConcrete.class, reader);
}
}
org.simpleframework.xml.stream.NodeReader.readValue(InputNode) returns
null in this case instead of empty string and this leads to
deserialization fail. Could you suggest any workarounds?
|