https://issues.apache.org/jira/browse/AMQ-4180 - force unmarshaling for maps and lists

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1424587 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2012-12-20 16:53:33 +00:00
parent 9383e56043
commit 3a6bbfe51f
1 changed files with 23 additions and 12 deletions

View File

@ -92,7 +92,7 @@ public final class MarshallingSupport {
Map<String, Object> rc = new HashMap<String, Object>(size);
for (int i = 0; i < size; i++) {
String name = in.readUTF();
rc.put(name, unmarshalPrimitive(in));
rc.put(name, unmarshalPrimitive(in, true));
}
return rc;
}
@ -110,7 +110,7 @@ public final class MarshallingSupport {
int size = in.readInt();
List<Object> answer = new ArrayList<Object>(size);
while (size-- > 0) {
answer.add(unmarshalPrimitive(in));
answer.add(unmarshalPrimitive(in, true));
}
return answer;
}
@ -152,6 +152,10 @@ public final class MarshallingSupport {
}
public static Object unmarshalPrimitive(DataInputStream in) throws IOException {
return unmarshalPrimitive(in, false);
}
public static Object unmarshalPrimitive(DataInputStream in, boolean force) throws IOException {
Object value = null;
byte type = in.readByte();
switch (type) {
@ -183,18 +187,19 @@ public final class MarshallingSupport {
value = new byte[in.readInt()];
in.readFully((byte[])value);
break;
case STRING_TYPE: {
int length = in.readUnsignedShort();
byte data[] = new byte[length];
in.readFully(data);
value = new UTF8Buffer(data);
case STRING_TYPE:
if (force) {
value = in.readUTF();
} else {
value = readUTF(in, in.readUnsignedShort());
}
break;
}
case BIG_STRING_TYPE: {
int length = in.readInt();
byte data[] = new byte[length];
in.readFully(data);
value = new UTF8Buffer(data);
if (force) {
value = readUTF8(in);
} else {
value = readUTF(in, in.readInt());
}
break;
}
case MAP_TYPE:
@ -212,6 +217,12 @@ public final class MarshallingSupport {
return value;
}
public static UTF8Buffer readUTF(DataInputStream in, int length) throws IOException {
byte data[] = new byte[length];
in.readFully(data);
return new UTF8Buffer(data);
}
public static void marshalNull(DataOutputStream out) throws IOException {
out.writeByte(NULL);
}