How do I serialize a complex Map object?

I have to pass an object across a system where I can only transmit strings. Serialization is perfect for what I need but I can't get this metrics object to serialize properly.

Java creating the object:

Map> metrics = new HashMap>();

String serializedObject = "";

try {

ByteArrayOutputStream bo = new ByteArrayOutputStream();

ObjectOutputStream so = new ObjectOutputStream(bo);

so.writeObject(metrics);

so.close();

serializedObject = bo.toString();

} catch (Exception e) {

System.out.println(e);

}

…pass serializedObject as a String…

Java desterilizing the object back into a metrics object.

Map> metrics = new HashMap>();

try {

byte b[] = serializedObject.getBytes();

ByteArrayInputStream bi = new...

Read More »

By: StackOverFlow - Monday, 5 November

Related Posts