Permalink
Browse files

Fixed Issue #74, java.util.Locale serialization error

  • Loading branch information...
1 parent 8ff1d77 commit 67a5d6ff2e2be12f77851894b4ad4fe25770f76d @dan-g dan-g committed Apr 29, 2012
@@ -21,8 +21,6 @@
import java.math.BigInteger;
import java.util.*;
-import net.kotek.jdbm.SerialClassInfo.ClassInfo;
-
import static net.kotek.jdbm.SerializationHeader.*;
/**
@@ -387,6 +385,12 @@ else if (val == 1)
serializeMap(HASHTABLE, out, obj, objectStack);
} else if (clazz == Properties.class) {
serializeMap(PROPERTIES, out, obj, objectStack);
+ } else if (clazz == Locale.class){
+ out.write(LOCALE);
+ Locale l = (Locale) obj;
+ out.writeUTF(l.getLanguage());
+ out.writeUTF(l.getCountry());
+ out.writeUTF(l.getVariant());
} else {
out.write(NORMAL);
writeObject(out, obj, objectStack);
@@ -858,6 +862,9 @@ public Object deserialize(DataInput is, FastArrayList objectStack) throws IOExce
case ARRAY_BYTE_INT:
ret = deserializeArrayByteInt(is);
break;
+ case LOCALE :
+ ret = new Locale(is.readUTF(),is.readUTF(),is.readUTF());
+ break;
case JDBMLINKEDLIST:
ret = LinkedList2.deserialize(is, this);
break;
@@ -113,17 +113,14 @@
final static int NOTUSED_VECTOR_255 = 120;
final static int VECTOR = 121;
- final static int NOTUSED_HASHTABLE_255 = 122;
+ final static int IDENTITYHASHMAP = 122;
final static int HASHTABLE = 123;
- final static int NOTUSED_PROPERTIES_255 = 124;
+ final static int LOCALE = 124;
final static int PROPERTIES = 125;
final static int CLASS = 126;
-
final static int DATE = 127;
- final static int NOTUSED_IDENTITYHASHMAP = 128;
- final static int IDENTITYHASHMAP = 129;
static final int JDBMLINKEDLIST = 159;
static final int HTREE = 160;
@@ -401,6 +401,14 @@ public void testBigInteger() throws IOException, ClassNotFoundException {
}
+ public void testLocale() throws Exception{
+ assertEquals(Locale.FRANCE, ser.deserialize(ser.serialize(Locale.FRANCE)));
+ assertEquals(Locale.CANADA_FRENCH, ser.deserialize(ser.serialize(Locale.CANADA_FRENCH)));
+ assertEquals(Locale.SIMPLIFIED_CHINESE, ser.deserialize(ser.serialize(Locale.SIMPLIFIED_CHINESE)));
+ assertEquals(Locale.UNICODE_LOCALE_EXTENSION, ser.deserialize(ser.serialize(Locale.UNICODE_LOCALE_EXTENSION)));
@ifedorenko
ifedorenko Apr 30, 2012

Locale.UNICODE_LOCALE_EXTENSION was introduced in Java 7 and this code won't compile on earlier JDK versions. The last assert does not seem to be essential, so I wonder if it can be removed to restore Java 1.5+ build compatibility.

@jankotek
jankotek via email Apr 30, 2012 Owner
+
+ }
+
}

0 comments on commit 67a5d6f

Please sign in to comment.