Got a class that serializes into xml with XMLEncoder nicely with all the variables there. Except for the one that holds java.util.Locale. What could be the trick?
Got a class that serializes into xml with XMLEncoder nicely with all the variables
Share
The problem is that java.util.Locale is not a bean. From the XMLEncoder doc:
However, the API allows you to use PersistenceDelegates to serialize non-bean types:
Sample bean:
Serializing a data graph that includes a Locale type:
This is the section of code that describes how the object should be instantiated on deserialization – it sets the constructor arguments to three string values:
Read Using XMLEncoder by Philip Milne for more info.
All this aside, it might be smarter to store the locale information in textual form and use it to look up the appropriate Locale object whenever it is needed. That way you don’t need special case code when serializing your object and make it more portable.