private BeanMap parseIntoBeanMap2()

in juneau-core/juneau-marshall/src/main/java/org/apache/juneau/json/JsonParserSession.java [631:719]


	private <T> BeanMap<T> parseIntoBeanMap2(ParserReader r, BeanMap<T> m) throws IOException, ParseException, ExecutableException {

		int S0=0; // Looking for outer {
		int S1=1; // Looking for attrName start.
		int S3=3; // Found attrName end, looking for :.
		int S4=4; // Found :, looking for valStart: { [ " ' LITERAL.
		int S5=5; // Looking for , or }

		int state = S0;
		String currAttr = "";
		int c = 0;
		mark();
		try {
			while (c != -1) {
				c = r.read();
				if (state == S0) {
					if (c == '{') {
						state = S1;
					} else if (isCommentOrWhitespace(c)) {
						skipCommentsAndSpace(r.unread());
					} else {
						break;
					}
				} else if (state == S1) {
					if (c == '}') {
						return m;
					} else if (isCommentOrWhitespace(c)) {
						skipCommentsAndSpace(r.unread());
					} else {
						r.unread();
						mark();
						currAttr = parseFieldName(r);
						state = S3;
					}
				} else if (state == S3) {
					if (c == ':')
						state = S4;
				} else if (state == S4) {
					if (isCommentOrWhitespace(c)) {
						skipCommentsAndSpace(r.unread());
					} else {
						if (! currAttr.equals(getBeanTypePropertyName(m.getClassMeta()))) {
							BeanPropertyMeta pMeta = m.getPropertyMeta(currAttr);
							setCurrentProperty(pMeta);
							if (pMeta == null) {
								onUnknownProperty(currAttr, m, parseAnything(object(), r.unread(), m.getBean(false), null));
								unmark();
							} else {
								unmark();
								ClassMeta<?> cm = pMeta.getClassMeta();
								Object value = parseAnything(cm, r.unread(), m.getBean(false), pMeta);
								setName(cm, value, currAttr);
								try {
									pMeta.set(m, currAttr, value);
								} catch (BeanRuntimeException e) {
									onBeanSetterException(pMeta, e);
									throw e;
								}
							}
							setCurrentProperty(null);
						}
						state = S5;
					}
				} else if (state == S5) {
					if (c == ',')
						state = S1;
					else if (isCommentOrWhitespace(c))
						skipCommentsAndSpace(r.unread());
					else if (c == '}') {
						return m;
					}
				}
			}
			if (state == S0)
				throw new ParseException(this, "Expected '{' at beginning of JSON object.");
			if (state == S1)
				throw new ParseException(this, "Could not find attribute name on JSON object.");
			if (state == S3)
				throw new ParseException(this, "Could not find ':' following attribute name on JSON object.");
			if (state == S4)
				throw new ParseException(this, "Expected one of the following characters: {,[,',\",LITERAL.");
			if (state == S5)
				throw new ParseException(this, "Could not find '}' marking end of JSON object.");
		} finally {
			unmark();
		}

		return null; // Unreachable.
	}