// The key is an undelimited string; it must adhere to Java
// identifier syntax
StringBuilder keyBuilder = new StringBuilder();
if (!Character.isJavaIdentifierStart(c)) {
throw new SerializationException("Illegal identifier start character.");
}
while (c != -1
&& c != ':' && !Character.isWhitespace(c)) {
if (!Character.isJavaIdentifierPart(c)) {
throw new SerializationException("Illegal identifier character.");
}
keyBuilder.append((char)c);
c = reader.read();
}
if (c == -1) {
throw new SerializationException("Unexpected end of input stream.");
}
key = keyBuilder.toString();
}
if (key == null
|| key.length() == 0) {
throw new SerializationException("\"" + key + "\" is not a valid key.");
}
// Notify listeners
if (jsonSerializerListeners != null) {
jsonSerializerListeners.readKey(this, key);
}
skipWhitespaceAndComments(reader);
if (c != ':') {
throw new SerializationException("Unexpected character in input stream.");
}
// Move to the first character after ':'
c = reader.read();
if (valueType == null) {
// The map is a bean instance; get the generic type of the property
Type genericValueType = ((BeanAdapter)dictionary).getGenericType(key);
if (genericValueType != null) {
// Set the value in the bean
dictionary.put(key, readValue(reader, genericValueType));
} else {
// The property does not exist; ignore this value
readValue(reader, Object.class);
}
} else {
dictionary.put(key, readValue(reader, valueType));
}
skipWhitespaceAndComments(reader);
if (c == ',') {
c = reader.read();
skipWhitespaceAndComments(reader);
} else if (c == -1) {
throw new SerializationException("Unexpected end of input stream.");
} else {
if (c != '}') {
throw new SerializationException("Unexpected character in input stream.");
}
}
}
// Move to the first character after '}'