Re: [Simple-support] can't serialize an object which uses aparametrized hashmap
Brought to you by:
niallg
|
From: <Nia...@ub...> - 2009-04-01 15:05:41
|
Hi,
This is because T does not exist. In java the generic type T used to
parameterize MyMap disappears after compilation. It's a process called
erasure and it means that the type can not be acquired reflectively at
runtime. There is talk of Java 7 resolving this issue but for Java 5 and
6 you will not be able to execute the code you have provided.
Niall
-----Original Message-----
From: Joe [mailto:fis...@ya...]
Sent: 01 April 2009 15:45
To: sim...@li...
Subject: [Simple-support] can't serialize an object which uses
aparametrized hashmap
Hi,
the following code throws an exception.
But if i replace T by String, serialization is no problem.
Why the parametrized version doesn't work?
Version: 2.0.4
import java.io.File;
import java.util.HashMap;
import org.simpleframework.xml.ElementMap;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
public class MyMap<T>
{
@ElementMap
private HashMap<T, String> map = new HashMap<T, String>();
public static void main(String[] args)
{
try
{
serialize(new MyMap<String>());
System.out.println("done");
}
catch (Exception e)
{
e.printStackTrace();
}
}
private static void serialize(Object data) throws Exception
{
Serializer serializer = new Persister();
File xmlFile = new File("test.xml");
serializer.write(data, xmlFile);
}
}
------------------------------------------------------------------------
------
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
Visit our website at http://www.ubs.com
This message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this e-mail. Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.
E-mails are not encrypted and cannot be guaranteed to be secure or
error-free as information could be intercepted, corrupted, lost,
destroyed, arrive late or incomplete, or contain viruses. The sender
therefore does not accept liability for any errors or omissions in the
contents of this message which arise as a result of e-mail transmission.
If verification is required please request a hard-copy version. This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities
or related financial instruments.
UBS Limited is a company registered in England & Wales under company
number 2035362, whose registered office is at 1 Finsbury Avenue,
London, EC2M 2PP, United Kingdom.
UBS AG (London Branch) is registered as a branch of a foreign company
under number BR004507, whose registered office is at
1 Finsbury Avenue, London, EC2M 2PP, United Kingdom.
UBS Clearing and Execution Services Limited is a company registered
in England & Wales under company number 03123037, whose registered
office is at 1 Finsbury Avenue, London, EC2M 2PP, United Kingdom.
|