protected Either<L, R> create(JsonToken nextToken, JsonReader in) throws IOException { boolean matchesLeft = left.isAssignable(nextToken); boolean matchesRight = right.isAssignable(nextToken); if (matchesLeft && matchesRight) { if (leftChecker != null || rightChecker != null) { JsonElement element = new JsonParser().parse(in); if (leftChecker != null && leftChecker.test(element)) // Parse the left alternative from the JSON element tree return createLeft(left.read(element)); if (rightChecker != null && rightChecker.test(element)) // Parse the right alternative from the JSON element tree return createRight(right.read(element)); } throw new JsonParseException("Ambiguous Either type: token " + nextToken + " matches both alternatives."); } else if (matchesLeft) { // Parse the left alternative from the JSON stream return createLeft(left.read(in)); } else if (matchesRight) { // Parse the right alternative from the JSON stream return createRight(right.read(in)); } else { throw new JsonParseException("Unexpected token " + nextToken + ": expected " + left + " | " + right + " tokens."); } }
protected Either<L, R> create(JsonToken nextToken, JsonReader in) throws IOException { boolean matchesLeft = left.isAssignable(nextToken); boolean matchesRight = right.isAssignable(nextToken); if (matchesLeft && matchesRight) { if (leftChecker != null || rightChecker != null) { JsonElement element = new JsonParser().parse(in); if (leftChecker != null && leftChecker.test(element)) // Parse the left alternative from the JSON element tree return createLeft(left.read(element)); if (rightChecker != null && rightChecker.test(element)) // Parse the right alternative from the JSON element tree return createRight(right.read(element)); } throw new JsonParseException("Ambiguous Either type: token " + nextToken + " matches both alternatives."); } else if (matchesLeft) { // Parse the left alternative from the JSON stream return createLeft(left.read(in)); } else if (matchesRight) { // Parse the right alternative from the JSON stream return createRight(right.read(in)); } else { throw new JsonParseException("Unexpected token " + nextToken + ": expected " + left + " | " + right + " tokens."); } }