Reputation: 492
I have been struggling with a problem about Kryo. I have a client server architecture and sending message via JMS using Kryo. In one of my response class I have a class having javax.xml.datatype.Duration
class as attribute. There is no chance for me to change it since it is in an interface of two software.
In the error stack, it gives this class having the problem: com.sun.org.apache.xerces.internal.jaxp.datatype.DurationImpl
. I do not use it in anywhere in my code. I have written some code to say Kryo to how to serialize javax.xml.datatype.Duration class like this:
public Duration read(kryoi input, entryClass){
return DataTypeFactory.newInstance().newDuration((String)kryo.readClassAndObject(input));
}
public void write(kryo, out, entryclass){
kryo.writeClassAndObject(out, entryClass.toString());
}
This does not solve the problem. I would like to achieve com.sun.org.apache.xerces.internal.jaxp.datatype.DurationImpl class object to write Kryo serializer for it. However I have no access for the class. How could I solve it?
Thanks in advance
Upvotes: 1
Views: 5649
Reputation: 61
Implement a DurationSerializer
as:
class DurationSerializer extends FieldSerializer<Duration> {
@Override
public void write (Kryo kryo, Output output, Duration object) {
output.writeString(object.toString());
}
@Override
public Duration read(Kryo kryo, Input input, Class<? extends Duration> type) {
try {
return DatatypeFactory.newInstance().newDuration(input.readString());
} catch (DatatypeConfigurationException e) {
throw new RuntimeException(e);
}
}
}
Then register it as Serializer
for the Duration
implementation of your JAXP library as:
kryo.register(datatypeFactory.newDuration(1000).getClass(), new DurationSerializer());
Upvotes: 1