Java Code Examples for com.fasterxml.jackson.databind.exc.MismatchedInputException#from()

The following examples show how to use com.fasterxml.jackson.databind.exc.MismatchedInputException#from() . 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: ObjectMapper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method called to ensure that given parser is ready for reading
 * content for data binding.
 *
 * @return First token to be used for data binding after this call:
 *  can never be null as exception will be thrown if parser cannot
 *  provide more tokens.
 *
 * @throws IOException if the underlying input source has problems during
 *   parsing
 * @throws JsonParseException if parser has problems parsing content
 * @throws JsonMappingException if the parser does not have any more
 *   content to map (note: Json "null" value is considered content;
 *   enf-of-stream not)
 */
protected JsonToken _initForReading(JsonParser p, JavaType targetType) throws IOException
{
    _deserializationConfig.initialize(p); // since 2.5

    // First: must point to a token; if not pointing to one, advance.
    // This occurs before first read from JsonParser, as well as
    // after clearing of current token.
    JsonToken t = p.getCurrentToken();
    if (t == null) {
        // and then we must get something...
        t = p.nextToken();
        if (t == null) {
            // Throw mapping exception, since it's failure to map,
            //   not an actual parsing problem
            throw MismatchedInputException.from(p, targetType,
                    "No content to map due to end-of-input");
        }
    }
    return t;
}
 
Example 2
Source File: CloudEventDeserializer.java    From sdk-java with Apache License 2.0 5 votes vote down vote up
private String getStringNode(ObjectNode objNode, JsonParser p, String attributeName) throws JsonProcessingException {
    String val = getOptionalStringNode(objNode, p, attributeName);
    if (val == null) {
        throw MismatchedInputException.from(p, CloudEvent.class, "Missing mandatory " + attributeName + " attribute");
    }
    return val;
}
 
Example 3
Source File: CloudEventDeserializer.java    From sdk-java with Apache License 2.0 5 votes vote down vote up
private void assertNodeType(JsonNode node, JsonNodeType type, String attributeName, String desc) throws JsonProcessingException {
    if (node.getNodeType() != type) {
        throw MismatchedInputException.from(
            p,
            CloudEvent.class,
            "Wrong type " + node.getNodeType() + " for attribute " + attributeName + ", expecting " + type + (desc != null ? ". " + desc : "")
        );
    }
}
 
Example 4
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method used to indicate a problem with input in cases where more
 * specific <code>reportXxx()</code> method was not available.
 *
 * @since 2.9
 */
public <T> T reportInputMismatch(BeanProperty prop,
        String msg, Object... msgArgs) throws JsonMappingException
{
    msg = _format(msg, msgArgs);
    JavaType type = (prop == null) ? null : prop.getType();
    throw MismatchedInputException.from(getParser(), type, msg);
}
 
Example 5
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method used to indicate a problem with input in cases where more
 * specific <code>reportXxx()</code> method was not available.
 *
 * @since 2.9
 */
public <T> T reportInputMismatch(JsonDeserializer<?> src,
        String msg, Object... msgArgs) throws JsonMappingException
{
    msg = _format(msg, msgArgs);
    throw MismatchedInputException.from(getParser(), src.handledType(), msg);
}
 
Example 6
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method used to indicate a problem with input in cases where more
 * specific <code>reportXxx()</code> method was not available.
 *
 * @since 2.9
 */
public <T> T reportInputMismatch(Class<?> targetType,
        String msg, Object... msgArgs) throws JsonMappingException
{
    msg = _format(msg, msgArgs);
    throw MismatchedInputException.from(getParser(), targetType, msg);
}
 
Example 7
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method used to indicate a problem with input in cases where more
 * specific <code>reportXxx()</code> method was not available.
 *
 * @since 2.9
 */
public <T> T reportInputMismatch(JavaType targetType,
        String msg, Object... msgArgs) throws JsonMappingException
{
    msg = _format(msg, msgArgs);
    throw MismatchedInputException.from(getParser(), targetType, msg);
}
 
Example 8
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public <T> T reportTrailingTokens(Class<?> targetType,
            JsonParser p, JsonToken trailingToken) throws JsonMappingException
    {
        throw MismatchedInputException.from(p, targetType, String.format(
"Trailing token (of type %s) found after value (bound as %s): not allowed as per `DeserializationFeature.FAIL_ON_TRAILING_TOKENS`",
trailingToken, ClassUtil.nameOf(targetType)
                ));
    }
 
Example 9
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public JsonMappingException wrongTokenException(JsonParser p, Class<?> targetType,
        JsonToken expToken, String extra)
{
    String msg = String.format("Unexpected token (%s), expected %s",
            p.getCurrentToken(), expToken);
    msg = _colonConcat(msg, extra);
    return MismatchedInputException.from(p, targetType, msg);
}
 
Example 10
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 2.5
 *
 * @deprecated Since 2.8 use {@link #handleUnknownTypeId} instead
 */
@Deprecated
public JsonMappingException unknownTypeException(JavaType type, String id,
        String extraDesc)
{
    String msg = String.format("Could not resolve type id '%s' into a subtype of %s",
            id, type);
    msg = _colonConcat(msg, extraDesc);
    return MismatchedInputException.from(_parser, type, msg);
}
 
Example 11
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Helper method for constructing {@link JsonMappingException} to indicate
 * that the token encountered was of type different than what <b>should</b>
 * be seen at that position, usually within a sequence of expected tokens.
 * Note that most of the time this method should NOT be directly called;
 * instead, {@link #reportWrongTokenException} should be called and will
 * call this method as necessary.
 *
 * @since 2.9
 */
public JsonMappingException wrongTokenException(JsonParser p, JavaType targetType,
        JsonToken expToken, String extra)
{
    String msg = String.format("Unexpected token (%s), expected %s",
            p.getCurrentToken(), expToken);
    msg = _colonConcat(msg, extra);
    return MismatchedInputException.from(p, targetType, msg);
}
 
Example 12
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * @since 2.8
 *
 * @deprecated Since 2.9: not clear this ever occurs
 */
@Deprecated // since 2.9
public void reportMissingContent(String msg, Object... msgArgs) throws JsonMappingException {
    throw MismatchedInputException.from(getParser(), (JavaType) null, "No content to map due to end-of-input");
}
 
Example 13
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Helper method for constructing exception to indicate that end-of-input was
 * reached while still expecting more tokens to deserialize value of specified type.
 *
 * @deprecated Since 2.8; currently no way to catch EOF at databind level
 */
@Deprecated
public JsonMappingException endOfInputException(Class<?> instClass) {
    return MismatchedInputException.from(_parser, instClass,
            "Unexpected end-of-input when trying to deserialize a "+instClass.getName());
}