hi everybody!
classes:
Class A: contains a List<Class B>
Class B: contains a List<Class C>
Class C: simple POJO
when i write Class A i get a very nice and correct xml. but when i try
to read the xml the Class A list contains nothing.
what can i do?
please consider attachment to see my code i use.
using betwixt 0.8
thx
package com.avenum.avedium.modules.jobmanager.backend.services.datasource.transcode;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import org.apache.commons.betwixt.io.BeanReader;
import org.apache.commons.betwixt.io.BeanWriter;
import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.avenum.avedium.common.lang.LogUtils;
import com.avenum.avedium.common.model.criteria.AvediumCriteriaList;
import com.avenum.avedium.modules.jobmanager.backend.exception.TranscodeException;
import com.avenum.avedium.modules.jobmanager.backend.services.datasource.transcode.betwixt.EnumObjectStringConverter;
import com.avenum.avedium.modules.jobmanager.backend.services.datasource.transcode.betwixt.EnumTypeBindingStrategy;
/**
* implementation of [EMAIL PROTECTED] GenericTranscoder} for [EMAIL PROTECTED] AvediumCriteriaList}, which transcodes
* from xml-String <-> object. this implementation uses Betwixt
* @author eckobar
* @since 1.0.0
*/
public class CriteriaListXmlTranscoder implements GenericTranscoder<String, AvediumCriteriaList>
{
/*
* CONSTANTS
*/
private static final Log LOG = LogFactory.getLog(CriteriaListXmlTranscoder.class);
private static final String OBJECT_ID = "criteriaList";
/**
* @see com.avenum.avedium.modules.jobmanager.backend.services.datasource.transcode.GenericTranscoder#decode(java.lang.Object)
*/
public AvediumCriteriaList decode(String data) throws TranscodeException
{
try
{
LOG.debug("decoding data...");
LOG.trace(LogUtils.buildPairChain("data", data));
StopWatch watch = new StopWatch();
watch.start();
LOG.debug("setting up reader...");
StringReader reader = new StringReader(data);
BeanReader beanReader = new BeanReader();
LOG.debug("setting beanreader config");
beanReader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
beanReader.getBindingConfiguration().setMapIDs(false);
beanReader.getXMLIntrospector().getConfiguration().setTypeBindingStrategy(new EnumTypeBindingStrategy());
beanReader.getBindingConfiguration().setObjectStringConverter(new EnumObjectStringConverter());
LOG.debug("register class...");
beanReader.registerBeanClass(OBJECT_ID, AvediumCriteriaList.class);
LOG.debug("parsing...");
AvediumCriteriaList result = (AvediumCriteriaList) beanReader.parse(reader);
watch.stop();
LOG.debug("end decoding data" + LogUtils.buildPairChain("result", result, "duration", watch.getTime()));
return result;
}
catch (Exception e)
{
throw new TranscodeException("error during decode object", e);
}
}
/**
* @see com.avenum.avedium.modules.jobmanager.backend.services.datasource.transcode.GenericTranscoder#encode(java.lang.Object)
*/
public String encode(AvediumCriteriaList o) throws TranscodeException
{
Writer writer = null;
BeanWriter beanwriter = null;
try
{
LOG.debug("encoding object..." + LogUtils.buildPairChain("object", o));
StopWatch watch = new StopWatch();
watch.start();
LOG.debug("setting up writer");
writer = new StringWriter();
writer.write("<?xml version='1.0' ?>");
beanwriter = new BeanWriter(writer);
LOG.debug("setting beanwriter configuration");
beanwriter.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
beanwriter.getBindingConfiguration().setMapIDs(false);
beanwriter.getXMLIntrospector().getConfiguration().setTypeBindingStrategy(new EnumTypeBindingStrategy());
beanwriter.getBindingConfiguration().setObjectStringConverter(new EnumObjectStringConverter());
beanwriter.enablePrettyPrint();
LOG.debug("writing object...");
beanwriter.write(OBJECT_ID, o);
String result = writer.toString();
watch.stop();
LOG.trace(LogUtils.buildPairChain(OBJECT_ID, result));
LOG.debug("end encoding object..." + LogUtils.buildPairChain("duration", watch.getTime()));
return result;
}
catch (Exception e)
{
throw new TranscodeException("error during decode object", e);
}
finally
{
this.closeWriter(writer);
}
}
/**
* close writer in secure way
*
* @param writer, writer to close
*/
protected void closeWriter(Writer writer)
{
try
{
if (writer != null)
{
writer.close();
}
}
catch (Exception e)
{
LOG.error("error during close writer", e);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]