-----Original Message-----
From: Lars Lindgren [mailto:[EMAIL PROTECTED]]
Sent: Thursday, July 11, 2002 10:16 AM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Mapping file bug in Castor 0.9.3.19Hi!If I marshall the Meti instance, i.e. item, instead of the Invoice instance, i.e. invoice, the NullPointerException does not occur. So probably your assumption is correct.Thanks for your help!Best regards
Lars-----Original Message-----
From: S�bastien Gignoux [mailto:[EMAIL PROTECTED]]
Sent: den 11 juli 2002 10:09
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Mapping file bug in Castor 0.9.3.19Hi,I reproduced your problem, here is the stack trace with the line numbers:java.lang.NullPointerException
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:953)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1266)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1270)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:721)
at Invoice.main(Invoice.java:54)The problem seems to come from the fact that there is mapping information for the class Meti but not for Invoice, its parent. I will try to look at it more closely.Seb-----Original Message-----
From: Lars Lindgren [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 10, 2002 6:31 PM
To: [EMAIL PROTECTED]
Subject: [castor-dev] Mapping file bug in Castor 0.9.3.19Hi!
Some days ago I sent a mail asking for help with a mapping file that didn't work. Now I have been downloading different versions of
xerces, jdk and so on to try what could possibly be the problem with the NullPointerException that I had. Finally I tried to change version
of Castor to 0.9.3.9 that is also available via the ftp. Then my mapping file was accepted with no problem.
When using Castor 0.9.3.19 I get the following stack trace when using the code examples below:
java.lang.NullPointerException
at org.exolab.castor.xml.Marshaller.marshal(Compiled Code)
at org.exolab.castor.xml.Marshaller.marshal(Compiled Code)
at org.exolab.castor.xml.Marshaller.marshal(Compiled Code)
at org.exolab.castor.xml.Marshaller.marshal(Compiled Code)
at Invoice.main(Invoice.java:53)The stack trace is not very informative. If you download the source code the stack trace shows that there is some class descriptor that is null.
A copy of my previous mail is below and it also contains my test program and the mapping file that I used.
Best regards
Lars==============================================================================================
Hi!I have problem using a mapping file in Castor. I have made a test example where I marshall an Invoice class to file. The invoice
class has a vector of items of type Meti (that is Item backwards). What I want to test is to save all the Meti class instances as
item tags in the xml file. The reason for doing that is that I want to test if it is possible to change the name of a class but still be
able to read the data from the xml file.
The problem is that when I don't use the mapping file everything is well, but when use the mapping file
the program stops with a NullPointerException. So I guess that the problem is my mapping file, but I cannot figure out what the problemis. With the mapping file below I want to save the Meti class as item tags and not meti tags.
I would really appreciate some help. I am new to Castor, and the reason that I want to use it is to design a saving utility where it
is possible to change the name of classes, and still be able to read old saved data.
Thanks in advance!
Best regards
LarsMy mapping class is the following:
-----------------------------------------------------------------
<mapping>
<class name="Meti">
<map-to xml="item" />
</class>
</mapping>My invoice class is the following:
-----------------------------------------------------------------
import java.io.*;
import java.util.Vector;import org.exolab.castor.mapping.*;
import org.exolab.castor.xml.*;public class Invoice {
private Vector item;public Invoice() {
item = new Vector();
}public void addItem(Meti item) {
this.item.add(item);
}public Vector getItem() {
return item;
}public void setItem(Vector items) {
item = items;
}public static void main(String[] argv) {
try {
Invoice invoice;
Meti item;
Mapping mapping = new Mapping();
mapping.loadMapping("mapping.xml");
item = new Meti();
item.setName("Milk");
item.setPrice(4);
item.setQuantity(10);
item.setProductSku("1234567890");
item.setDescription("From cows");
System.out.println("Invoice Item");
System.out.println("------------");
System.out.println("Product Name: " + item.getName());
System.out.println("Sku Number : " + item.getProductSku());
System.out.println("Price : " + item.getPrice());
System.out.println("Quantity : " + item.getQuantity());
invoice = new Invoice();
invoice.addItem(item);FileWriter writer = new FileWriter("invoice.xml");
Marshaller marshaller = new Marshaller(writer);
marshaller.setMapping(mapping); // With this commented out it works, but I want to use the mapping file.
marshaller.marshal(invoice);
writer.close();
}
catch (Exception e) {
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
}
}
----------------------------------------------------------------------
My Meti class is the following
---------------------------------------------------------------------
import java.io.*;import org.exolab.castor.xml.*;
public class Meti {
private int quantity;
private String description;
private String name;
private double price;
private String productSku;public Meti() {
}
public String getDescription() {
return description;
}public void setDescription(String desc) {
this.description = desc;
}
public String getName() {
return name;
}public void setName(String name) {
this.name = name;
}public double getPrice() {
return price;
}public void setPrice(double price) {
this.price = price;
}public String getProductSku() {
return productSku;
}
public void setProductSku(String sku) {
productSku = sku;
}public int getQuantity() {
return quantity;
}public void setQuantity(int quantity) {
this.quantity = quantity;
}
}
Title: Mapping file bug in Castor 0.9.3.19
Interresting. As
a temporary fix you could add the Invoice class to the mapping
file.
Regards
Seb
- Re: [castor-dev] Mapping file bug in Castor 0.9.3.19 S�bastien Gignoux
- Re: [castor-dev] Mapping file bug in Castor 0.9.3.1... S�bastien Gignoux
- Re: [castor-dev] Mapping file bug in Castor 0.9.3.1... Lars Lindgren
