使用Castor 1.3,在测试时收到以下例外:
org.exolab.castor.mapping.MappingException: The Java class com.company.sales.app.valueobjects.eai.ContactInformationValueObject$CommunicationPreference is not constructable -- it does not contain a default public constructor
试图在我的Java代码中使用公共内部类的集合。
类示例:
public class Car {
public String color;
public String make;
public String model;
public List<RoadTrip> roadTrips;
public class RoadTrip {
public String pointA;
public String pointB;
}
}
XML映射:
<class name="com.auto.Car" >
<field name="color" type="java.lang.String"><bind-xml name="COLOR" /></field>
<field name="make" type="java.lang.String"><bind-xml name="MAKE" /></field>
<field name="model" type="java.lang.String"><bind-xml name="MODEL" /></field>
<field name="roadTrips" type="com.auto.Car$RoadTrip"><bind-xml name="TRIP" /></field>
</class>
<class name="com.auto.Car$RoadTrip">
<field name="pointA" type="java.lang.String"><bind-xml name="STARTING_POINT" /></field>
<field name="pointB" type="java.lang.String"><bind-xml name="DESTINATION" /></field>
</class>
XML示例
<AUTOMOBILE>
<COLOR>LITTLE RED</COLOR>
<MAKE>CHEVROLET</MAKE>
<MODEL>CORVETTE</MODEL>
<TRIP>
<STARTING_POINT>DALLAS</STARTING_POINT>
<DESTINATION>VEGAS</DESTINATION>
</TRIP>
<TRIP>
<STARTING_POINT>SEATTLE</STARTING_POINT>
<DESTINATION>PORTLAND</DESTINATION>
</TRIP>
</AUTOMOBILE>
solved:我得到的原因是,我需要使我的内部阶级静态,以使Castor能够使用它。
网络周围其他地方有很多帖子,建议使用
verify-constructable="false"
但是内部班级缺少静态是一个简单的错误。希望它能帮助别人!
public class Car {
public String color;
public String make;
public String model;
public List<RoadTrip> roadTrips;
public static class RoadTrip {
public String pointA;
public String pointB;
}
}
http://castor.codehaus.org/1.2/how-to-map-anner-class.html