#17 Using an Interface for a Custom Converter Class

closed
None
5
2005-10-31
2005-10-30
No

Hello,

im working with version 1.5.5 for a couple of days.
Yesterday we must change a class to a interface.
This produces
"net.sf.dozer.util.mapping.MappingException:
java.lang.InstantiationException: BDT_Geldbetrag".

After implementing BDT_GeldbetragCustomConverter (see
below) i got now
"net.sf.dozer.util.mapping.converters.ConversionException:
String constructor does not exist in destination class:
interface BDT_Geldbetrag"

public interface BDT_Geldbetrag {
public static final String DEFAULT_WAEHRUNG = "EUR";

/**
* @return Returns the betrag.
*/
public BigDecimal getBetrag();

/**
* @param p_betrag
* The betrag to set.
*/
public void setBetrag(BigDecimal p_betrag);

/**
* @return Returns the waehrung.
*/
public String getWaehrung();

/**
* @param p_waehrung
* The waehrung to set.
*/
public void setWaehrung(String p_waehrung);
}

public class BDT_GeldbetragCustomConverter implements
CustomConverter {

/*
* (non-Javadoc)
*
* @see
net.sf.dozer.util.mapping.converters.CustomConverter#convert(java.lang.Object,

* java.lang.Object, java.lang.Class, java.lang.Class)
*/
public Object convert(Object destination, Object
source, Class destClass, Class sourceClass) {
BDT_GeldbetragImpl dest = null;
//BigDecimal -> BDT_GeldbetragImpl
if (source instanceof BigDecimal) {
// check to see if the object already exists
if (destination == null) {
dest = new BDT_GeldbetragImpl();
} else {
dest = (BDT_GeldbetragImpl) destination;
}
dest.setBetrag( (BigDecimal)source);
return dest;
//BDT_GeldbetragImpl -> BigDecimal
} else if (source instanceof BDT_GeldbetragImpl) {
return ((BDT_GeldbetragImpl) source).getBetrag();
} else {
throw new MappingException(
"Converter BDT_GeldbetragCustomConverter used
incorrectly. Arguments passed in were:"
+ destination + " and " + source);
}
}
}

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mappings PUBLIC "-//DOZER//DTD MAPPINGS//EN"
"http://dozer.sourceforge.net/dtd/dozerbeanmapping.dtd">
/><mappings>
<configuration>
<stopOnErrors>false</stopOnErrors>
<dateFormat>dd.MM.yyyy</dateFormat>
<wildcard>false</wildcard>
<customConverters> <!-- these are always bi-directional
-->
<!-- BDT_Geldbetrag -->
<converter type="BDT_GeldbetragCustomConverter" >
<classA>BDT_Geldbetrag</classA>
<classB>java.lang.BigDecimal</classB>
</converter>
</customConverters>
</configuration>
<mapping>
<classA>SiO_ImmobilieImpl</classA>
<classB>OImmobilie</classB>
<field>
<!-- BDT_Geldbetrag -->
<A>bewertungsBetragPersonalEuroIndividuell</A>
<!-- java.lang.BigDecimal -->
<B>belhGrenzewert</B>
</field>
</mapping>
</mappings>

My Question: What went wrong with the Converter, or how
can i specify a "concreteClass" ? Will the annonced
"Bean Factory Injection" in 1.5.6 help me ?

Regards

Matthias

Discussion

  • Franz Garsombke

    Franz Garsombke - 2005-10-30
    • status: open --> pending
     
  • Franz Garsombke

    Franz Garsombke - 2005-10-30

    Logged In: YES
    user_id=550744

    Fixed for 1.5.6

     
  • Franz Garsombke

    Franz Garsombke - 2005-10-31
    • status: pending --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks