RESOLVED - BATCH-821: remove EventSerializer/Deserializer abstractions and use Marshaller/Unmarshaller directly
cleanup of now redundant classes
This commit is contained in:
@@ -40,7 +40,7 @@ import org.springframework.xml.transform.StaxResult;
|
||||
|
||||
/**
|
||||
* An implementation of {@link ItemWriter} which uses StAX and
|
||||
* {@link EventWriterSerializer} for serializing object to XML.
|
||||
* {@link Marshaller} for serializing object to XML.
|
||||
*
|
||||
* This item writer also provides restart, statistics and transaction features
|
||||
* by implementing corresponding interfaces.
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package org.springframework.batch.item.xml.oxm;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.stream.XMLEventWriter;
|
||||
import javax.xml.transform.Result;
|
||||
|
||||
import org.springframework.batch.item.xml.EventWriterSerializer;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.xml.transform.StaxResult;
|
||||
|
||||
/**
|
||||
* Object to xml serializer that wraps a Spring OXM {@link Marshaller} object.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class MarshallingEventWriterSerializer<T> implements EventWriterSerializer<T> {
|
||||
|
||||
private Marshaller marshaller;
|
||||
|
||||
public MarshallingEventWriterSerializer(Marshaller marshaller) {
|
||||
this.marshaller = marshaller;
|
||||
}
|
||||
|
||||
public void serializeObject(XMLEventWriter writer, T output) {
|
||||
Result result = new StaxResult(writer);
|
||||
try {
|
||||
marshaller.marshal(output, result);
|
||||
}
|
||||
catch (IOException xse) {
|
||||
throw new DataAccessResourceFailureException("Unable to write to file resource: [" + result.getSystemId()
|
||||
+ "]", xse);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package org.springframework.batch.item.xml.oxm;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
|
||||
import org.springframework.batch.item.xml.EventReaderDeserializer;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.xml.transform.StaxSource;
|
||||
|
||||
/**
|
||||
* Delegates deserializing to Spring OXM {@link Unmarshaller}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
* @author Lucas Ward
|
||||
*/
|
||||
public class UnmarshallingEventReaderDeserializer<T> implements EventReaderDeserializer<T> {
|
||||
|
||||
private Unmarshaller unmarshaller;
|
||||
|
||||
public UnmarshallingEventReaderDeserializer(Unmarshaller unmarshaller){
|
||||
Assert.notNull(unmarshaller);
|
||||
this.unmarshaller = unmarshaller;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T deserializeFragment(XMLEventReader eventReader) {
|
||||
T item = null;
|
||||
try {
|
||||
item = (T) unmarshaller.unmarshal(new StaxSource(eventReader));
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new DataAccessResourceFailureException("IO error during unmarshalling", e);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user