Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
103 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.alibaba.com.caucho.hessian.io; | ||
|
||
import java.io.IOException; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Deserializing a uuid valued object | ||
**/ | ||
public class UUIDDeserializer extends AbstractDeserializer { | ||
|
||
@Override | ||
public Class getType() { | ||
return UUID.class; | ||
} | ||
|
||
@Override | ||
public Object readObject(AbstractHessianInput in) throws IOException { | ||
String uuidString = in.readString(); | ||
return UUID.fromString(uuidString); | ||
} | ||
|
||
@Override | ||
public Object readObject(AbstractHessianInput in, String[] fieldNames) throws IOException { | ||
String uuidString = in.readString(); | ||
return UUID.fromString(uuidString); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.alibaba.com.caucho.hessian.io; | ||
|
||
import com.alibaba.com.caucho.hessian.io.base.SerializeTestBase; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.util.*; | ||
|
||
import static junit.framework.TestCase.assertEquals; | ||
import static junit.framework.TestCase.assertTrue; | ||
|
||
/** | ||
* fix hessian serialize bug: | ||
* the uuid can not be deserialized properly | ||
**/ | ||
public class Hessian2UUIDTest extends SerializeTestBase { | ||
|
||
@Test | ||
public void testUUIDObject() throws IOException { | ||
UUID actual = UUID.randomUUID(); | ||
UUID deserialize = baseHessian2Serialize(actual); | ||
Assert.assertEquals(actual, deserialize); | ||
} | ||
|
||
@Test | ||
public void testUUIDList() throws IOException { | ||
List<UUID> actual = new ArrayList<>(2); | ||
actual.add(UUID.randomUUID()); | ||
actual.add(UUID.randomUUID()); | ||
|
||
ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
Hessian2Output out = new Hessian2Output(bout); | ||
|
||
out.writeObject(actual); | ||
out.flush(); | ||
|
||
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); | ||
Hessian2Input input = new Hessian2Input(bin); | ||
|
||
List<UUID> deserialize = (List) input.readObject(); | ||
assertTrue(deserialize != null); | ||
assertTrue(deserialize.size() == 2); | ||
assertEquals(actual, deserialize); | ||
} | ||
|
||
@Test | ||
public void testUUIDMap() throws IOException { | ||
Map<UUID, Object> actual = new HashMap<>(8); | ||
actual.put(UUID.randomUUID(), UUID.randomUUID()); | ||
actual.put(UUID.randomUUID(), null); | ||
|
||
ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
Hessian2Output out = new Hessian2Output(bout); | ||
|
||
out.writeObject(actual); | ||
out.flush(); | ||
|
||
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); | ||
Hessian2Input input = new Hessian2Input(bin); | ||
|
||
Map<UUID, Object> deserialize = (Map<UUID, Object>) input.readObject(); | ||
assertTrue(deserialize != null); | ||
assertTrue(deserialize.size() == 2); | ||
assertEquals(actual, deserialize); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters