com.mongodb.util.JSONParseException Java Examples

The following examples show how to use com.mongodb.util.JSONParseException. 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: DriverUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
static Object parseJSONExpr( String jsonExpr ) throws OdaException
{
    try
    {
        return JSON.parse( jsonExpr );
    }
    catch( JSONParseException ex )
    {
        String errMsg = Messages.bind( Messages.driverUtil_parsingError,
                jsonExpr );
        DriverUtil.getLogger().log( Level.INFO, errMsg, ex ); // caller may choose to ignore it; log at INFO level

        OdaException newEx = new OdaException( errMsg );
        newEx.initCause( ex );
        throw newEx;
    }
}
 
Example #2
Source File: QueryPanel.java    From nosql4idea with Apache License 2.0 6 votes vote down vote up
@Override
public MongoQueryOptions buildQueryOptions(String rowLimit) {
    MongoQueryOptions mongoQueryOptions = new MongoQueryOptions();
    try {
        mongoQueryOptions.setFilter(getQueryFrom(selectEditor));
        mongoQueryOptions.setProjection(getQueryFrom(projectionEditor));
        mongoQueryOptions.setSort(getQueryFrom(sortEditor));
    } catch (JSONParseException ex) {
        notifyOnErrorForOperator(selectEditor.getComponent(), ex);
    }

    if (StringUtils.isNotBlank(rowLimit)) {
        mongoQueryOptions.setResultLimit(Integer.parseInt(rowLimit));
    }

    return mongoQueryOptions;
}
 
Example #3
Source File: QueryPanel.java    From nosql4idea with Apache License 2.0 6 votes vote down vote up
void notifyOnErrorForOperator(JComponent component, Exception ex) {
    String message;
    if (ex instanceof JSONParseException) {
        message = StringUtils.removeStart(ex.getMessage(), "\n");
    } else {
        message = String.format("%s: %s", ex.getClass().getSimpleName(), ex.getMessage());
    }
    NonOpaquePanel nonOpaquePanel = new NonOpaquePanel();
    JTextPane textPane = Messages.configureMessagePaneUi(new JTextPane(), message);
    textPane.setFont(COURIER_FONT);
    textPane.setBackground(MessageType.ERROR.getPopupBackground());
    nonOpaquePanel.add(textPane, BorderLayout.CENTER);
    nonOpaquePanel.add(new JLabel(MessageType.ERROR.getDefaultIcon()), BorderLayout.WEST);

    JBPopupFactory.getInstance().createBalloonBuilder(nonOpaquePanel)
            .setFillColor(MessageType.ERROR.getPopupBackground())
            .createBalloon()
            .show(new RelativePoint(component, new Point(0, 0)), Balloon.Position.above);
}
 
Example #4
Source File: RestDestination.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private boolean isInvalidJson(String body) {
	if (StringUtils.isBlank(body)) {
           return true;
       }

	try {
           JSON.parse(body);
       } catch (JSONParseException e) {
           return true;
       }

	return false;
}
 
Example #5
Source File: ApplicationDocumentStoreServiceImpl.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private boolean isValidJson(String json) {

        if (StringUtils.isBlank(json)) {
            return false;
        } else {
            try {
                JSON.parse(json);
            } catch (JSONParseException e) {
                return false;
            }
        }

        return true;

    }
 
Example #6
Source File: DeviceConfigSetupServiceImpl.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private boolean isInvalidJson(String json) {

        if (StringUtils.isBlank(json)) {
            return true;
        }

        try {
            JSON.parse(json);
        } catch (JSONParseException e) {
            return true;
        }

        return false;
    }
 
Example #7
Source File: DeviceCustomDataServiceImpl.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private boolean isValidJson(String json) {

        if (StringUtils.isBlank(json)) {
            return false;
        } else {
            try {
                JSON.parse(json);
            } catch (JSONParseException e) {
                return false;
            }
        }

        return true;

    }
 
Example #8
Source File: JSON.java    From gameserver with Apache License 2.0 5 votes vote down vote up
/**
 * Read the current character, making sure that it is a hexidecimal character.
 * 
 * @throws JSONParseException
 *           if the current character is not a hexidecimal character
 */
public void readHex() {
	if (pos < s.length()
			&& ((s.charAt(pos) >= '0' && s.charAt(pos) <= '9')
					|| (s.charAt(pos) >= 'A' && s.charAt(pos) <= 'F') || (s.charAt(pos) >= 'a' && s
					.charAt(pos) <= 'f'))) {
		pos++;
	} else {
		throw new JSONParseException(s, pos);
	}
}
 
Example #9
Source File: JSON.java    From gameserver with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the next array.
 * 
 * @return the array
 * @throws JSONParseException
 *           if invalid JSON is found
 */
protected Object parseArray(String name) {
	if (name != null) {
		_callback.arrayStart(name);
	} else {
		_callback.arrayStart();
	}

	read('[');

	int i = 0;
	char current = get();
	while (current != ']') {
		String elemName = String.valueOf(i++);
		Object elem = parse(elemName);
		doCallback(elemName, elem);

		if ((current = get()) == ',') {
			read(',');
		} else if (current == ']') {
			break;
		} else {
			throw new JSONParseException(s, pos);
		}
	}

	read(']');

	return _callback.arrayDone();
}
 
Example #10
Source File: QueryPanel.java    From nosql4idea with Apache License 2.0 5 votes vote down vote up
@Override
public MongoQueryOptions buildQueryOptions(String rowLimit) {
    MongoQueryOptions mongoQueryOptions = new MongoQueryOptions();
    try {
        mongoQueryOptions.setOperations(getQuery());
    } catch (JSONParseException ex) {
        notifyOnErrorForOperator(editor.getComponent(), ex);
    }

    if (StringUtils.isNotBlank(rowLimit)) {
        mongoQueryOptions.setResultLimit(Integer.parseInt(rowLimit));
    }

    return mongoQueryOptions;
}
 
Example #11
Source File: JSON.java    From gameserver with Apache License 2.0 4 votes vote down vote up
/**
 * Parse an unknown type.
 * 
 * @return Object the next item
 * @throws JSONParseException
 *           if invalid JSON is found
 */
protected Object parse(String name) {
	Object value = null;
	char current = get();

	switch (current) {
	// null
		case 'n':
			read('n');
			read('u');
			read('l');
			read('l');
			value = null;
			break;
		// NaN
		case 'N':
			read('N');
			read('a');
			read('N');
			value = Double.NaN;
			break;
		// true
		case 't':
			read('t');
			read('r');
			read('u');
			read('e');
			value = true;
			break;
		// false
		case 'f':
			read('f');
			read('a');
			read('l');
			read('s');
			read('e');
			value = false;
			break;
		// string
		case '\'':
		case '\"':
			value = parseString(true);
			break;
		// number
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
		case '+':
		case '-':
			value = parseNumber();
			break;
		// array
		case '[':
			value = parseArray(name);
			break;
		// object
		case '{':
			value = parseObject(name);
			break;
		default:
			throw new JSONParseException(s, pos);
	}
	return value;
}
 
Example #12
Source File: JSON.java    From gameserver with Apache License 2.0 4 votes vote down vote up
/**
 * Parses a string.
 * 
 * @return the next string.
 * @throws JSONParseException
 *           if invalid JSON is found
 */
public String parseString(boolean needQuote) {
	char quot = 0;
	if (check('\''))
		quot = '\'';
	else if (check('\"'))
		quot = '\"';
	else if (needQuote)
		throw new JSONParseException(s, pos);

	char current;

	if (quot > 0)
		read(quot);
	StringBuilder buf = new StringBuilder();
	int start = pos;
	while (pos < s.length()) {
		current = s.charAt(pos);
		if (quot > 0) {
			if (current == quot)
				break;
		} else {
			if (current == ':' || current == ' ')
				break;
		}

		if (current == '\\') {
			pos++;

			char x = get();

			char special = 0;

			switch (x) {

				case 'u': { // decode unicode
					buf.append(s.substring(start, pos - 1));
					pos++;
					int tempPos = pos;

					readHex();
					readHex();
					readHex();
					readHex();

					int codePoint = Integer.parseInt(s.substring(tempPos, tempPos + 4),
							16);
					buf.append((char) codePoint);

					start = pos;
					continue;
				}
				case 'n':
					special = '\n';
					break;
				case 'r':
					special = '\r';
					break;
				case 't':
					special = '\t';
					break;
				case 'b':
					special = '\b';
					break;
				case '"':
					special = '\"';
					break;
				case '\\':
					special = '\\';
					break;
			}

			buf.append(s.substring(start, pos - 1));
			if (special != 0) {
				pos++;
				buf.append(special);
			}
			start = pos;
			continue;
		}
		pos++;
	}
	buf.append(s.substring(start, pos));
	if (quot > 0)
		read(quot);
	return buf.toString();
}
 
Example #13
Source File: EventParserTest.java    From ingestion with Apache License 2.0 4 votes vote down vote up
@Test(expected = JSONParseException.class)
public void parseBadJsonBodyToRow() {
    final EventParser eventParser = new EventParser(MappingDefinition.load("/simple_body_row_json.json"));
    eventParser.parse(EventBuilder.withBody("{???? \"foo\": \"bar\" }".getBytes(Charsets.UTF_8)));
}
 
Example #14
Source File: JSON.java    From gameserver with Apache License 2.0 3 votes vote down vote up
/**
 * Read the current character, making sure that it is the expected character.
 * Advances the pointer to the next character.
 * 
 * @param ch
 *          the character expected
 * 
 * @throws JSONParseException
 *           if the current character does not match the given character
 */
public void read(char ch) {
	if (!check(ch)) {
		throw new JSONParseException(s, pos);
	}
	pos++;
}