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

The following examples show how to use com.dslplatform.json.JsonReader#wasLastName() . 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
@Nullable
public T read(final JsonReader reader) throws IOException {
	if (reader.wasNull()) return null;
	else if (reader.last() != '{') {
		throw reader.newParseError(startError);
	}
	if (reader.getNextToken() == '}') {
		if (hasMandatory) {
			DecodePropertyInfo.showMandatoryError(reader, mandatoryFlag, decoders);
		}
		return newInstance.apply(defArgs);
	}
	final Object[] args = defArgs.clone();
	long currentMandatory = mandatoryFlag;
	int i = 0;
	while(i < decoders.length) {
		final DecodePropertyInfo<JsonReader.ReadObject> ri = decoders[i++];
		final int weakHash = reader.fillNameWeakHash();
		if (weakHash != ri.weakHash || !reader.wasLastName(ri.nameBytes)) {
			return readObjectSlow(args, reader, currentMandatory);
		}
		reader.getNextToken();
		if (ri.nonNull && reader.wasNull()) {
			throw reader.newParseErrorWith("Null value found for non-null attribute", ri.name);
		}
		args[ri.index] = ri.value.read(reader);
		currentMandatory = currentMandatory & ri.mandatoryValue;
		if (reader.getNextToken() == ',' && i != decoders.length) reader.getNextToken();
		else break;
	}
	return finalChecks(args, reader, currentMandatory);
}
 
Example 2
Source File: EnumDescription.java    From dsl-json with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
@Override
public T read(final JsonReader reader) throws IOException {
	if (reader.wasNull()) return null;
	final int hash = reader.calcHash();
	for (final DecodePropertyInfo<T> ri : decoders) {
		if (hash == ri.hash) {
			if (ri.exactName && !reader.wasLastName(ri.nameBytes)) continue;
			return ri.value;
		}
	}
	return Enum.valueOf(manifest, reader.getLastName());
}