Java Code Examples for com.dslplatform.json.JsonReader#newParseErrorFormat()

The following examples show how to use com.dslplatform.json.JsonReader#newParseErrorFormat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImmutableDescription.java    From dsl-json with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void skip(final JsonReader reader) throws IOException {
	if (!skipOnUnknown) {
		final String name = reader.getLastName();
		throw reader.newParseErrorFormat("Unknown property detected", name.length() + 3, "Unknown property detected: '%s' while reading %s", name, Reflection.typeDescription(manifest));
	}
	reader.getNextToken();
	reader.skip();
}
 
Example 2
Source File: MapDecoder.java    From dsl-json with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
@Override
public T read(JsonReader reader) throws IOException {
	if (reader.wasNull()) return null;
	if (reader.last() != '{') throw reader.newParseError("Expecting '{' for map start");
	final T instance;
	try {
		instance = newInstance.call();
	} catch (Exception e) {
		throw new ConfigurationException("Unable to create a new instance of " + Reflection.typeDescription(manifest), e);
	}
	if (reader.getNextToken() == '}') return instance;
	K key = keyDecoder.read(reader);
	if (key == null) {
		throw reader.newParseErrorFormat("Null value detected for key element of map", 0, "Null value detected for key element of %s", Reflection.typeDescription(manifest));
	}
	if (reader.getNextToken() != ':') throw reader.newParseError("Expecting ':' after key attribute");
	reader.getNextToken();
	V value = valueDecoder.read(reader);
	instance.put(key, value);
	while (reader.getNextToken() == ','){
		reader.getNextToken();
		key = keyDecoder.read(reader);
		if (key == null) throw reader.newParseErrorFormat("Null value detected for key element of map", 0, "Null value detected for key element of %s", Reflection.typeDescription(manifest));
		if (reader.getNextToken() != ':') throw reader.newParseError("Expecting ':' after key attribute");
		reader.getNextToken();
		value = valueDecoder.read(reader);
		instance.put(key, value);
	}
	if (reader.last() != '}') throw reader.newParseError("Expecting '}' as map ending");
	return instance;
}