Home / Function/ readLiteral() — spring-boot Function Reference

readLiteral() — spring-boot Function Reference

Architecture documentation for the readLiteral() function in JSONTokener.java from the spring-boot codebase.

Function java GradlePlugin RunTasks calls 2 called by 1

Entity Profile

Dependency Diagram

graph TD
  f4a17d8d_2d55_e198_454a_fcedac6674b9["readLiteral()"]
  87e46e8d_3da0_7f48_7371_9287ac91a438["nextValue()"]
  87e46e8d_3da0_7f48_7371_9287ac91a438 -->|calls| f4a17d8d_2d55_e198_454a_fcedac6674b9
  fe8b986e_5db0_a193_a005_7b747d465d34["nextToInternal()"]
  f4a17d8d_2d55_e198_454a_fcedac6674b9 -->|calls| fe8b986e_5db0_a193_a005_7b747d465d34
  2ea9368b_02eb_2d26_b6e7_aaf2153de2a0["syntaxError()"]
  f4a17d8d_2d55_e198_454a_fcedac6674b9 -->|calls| 2ea9368b_02eb_2d26_b6e7_aaf2153de2a0
  style f4a17d8d_2d55_e198_454a_fcedac6674b9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

configuration-metadata/spring-boot-configuration-metadata/src/json-shade/java/org/springframework/boot/configurationmetadata/json/JSONTokener.java lines 273–329

	private Object readLiteral() throws JSONException {
		String literal = nextToInternal("{}[]/\\:,=;# \t\f");

		if (literal.isEmpty()) {
			throw syntaxError("Expected literal value");
		}
		else if ("null".equalsIgnoreCase(literal)) {
			return JSONObject.NULL;
		}
		else if ("true".equalsIgnoreCase(literal)) {
			return Boolean.TRUE;
		}
		else if ("false".equalsIgnoreCase(literal)) {
			return Boolean.FALSE;
		}

		/* try to parse as an integral type... */
		if (literal.indexOf('.') == -1) {
			int base = 10;
			String number = literal;
			if (number.startsWith("0x") || number.startsWith("0X")) {
				number = number.substring(2);
				base = 16;
			}
			else if (number.startsWith("0") && number.length() > 1) {
				number = number.substring(1);
				base = 8;
			}
			try {
				long longValue = Long.parseLong(number, base);
				if (longValue <= Integer.MAX_VALUE && longValue >= Integer.MIN_VALUE) {
					return (int) longValue;
				}
				else {
					return longValue;
				}
			}
			catch (NumberFormatException e) {
				/*
				 * This only happens for integral numbers greater than Long.MAX_VALUE,
				 * numbers in exponential form (5e-10) and unquoted strings. Fall through
				 * to try floating point.
				 */
			}
		}

		/* ...next try to parse as a floating point... */
		try {
			return Double.valueOf(literal);
		}
		catch (NumberFormatException ex) {
			// Ignore
		}

		/* ... finally give up. We have an unquoted string */
		return new String(literal); // a new string avoids leaking memory
	}

Domain

Subdomains

Called By

Frequently Asked Questions

What does readLiteral() do?
readLiteral() is a function in the spring-boot codebase.
What does readLiteral() call?
readLiteral() calls 2 function(s): nextToInternal, syntaxError.
What calls readLiteral()?
readLiteral() is called by 1 function(s): nextValue.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free