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

The following examples show how to use com.fasterxml.jackson.databind.exc.InvalidDefinitionException#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: SerializerProvider.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper method called to indicate problem in POJO (serialization) definitions or settings
 * regarding specific property (of a type), unrelated to actual JSON content to map.
 * Default behavior is to construct and throw a {@link JsonMappingException}.
 *
 * @since 2.9
 */
public <T> T reportBadPropertyDefinition(BeanDescription bean, BeanPropertyDefinition prop,
        String message, Object... msgArgs) throws JsonMappingException {
    message = _format(message, msgArgs);
    String propName = "N/A";
    if (prop != null) {
        propName = _quotedString(prop.getName());
    }
    String beanDesc = "N/A";
    if (bean != null) {
        beanDesc = ClassUtil.nameOf(bean.getBeanClass());
    }
    message = String.format("Invalid definition for property %s (of type %s): %s",
            propName, beanDesc, message);
    throw InvalidDefinitionException.from(getGenerator(), message, bean, prop);
}
 
Example 2
Source File: CreatorProperty.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void _reportMissingSetter(JsonParser p, DeserializationContext ctxt) throws IOException
{
    final String msg = "No fallback setter/field defined for creator property '"+getName()+"'";
    // Hmmmh. Should we return quietly (NOP), or error?
    // Perhaps better to throw an exception, since it's generally an error.
    if (ctxt != null ) {
        ctxt.reportBadDefinition(getType(), msg);
    } else {
        throw InvalidDefinitionException.from(p, msg, getType());
    }
}
 
Example 3
Source File: SerializerProvider.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method called to indicate problem in POJO (serialization) definitions or settings
 * regarding specific Java type, unrelated to actual JSON content to map.
 * Default behavior is to construct and throw a {@link JsonMappingException}.
 *
 * @since 2.9
 */
public <T> T reportBadTypeDefinition(BeanDescription bean,
        String msg, Object... msgArgs) throws JsonMappingException {
    String beanDesc = "N/A";
    if (bean != null) {
        beanDesc = ClassUtil.nameOf(bean.getBeanClass());
    }
    msg = String.format("Invalid type definition for type %s: %s",
            beanDesc, _format(msg, msgArgs));
    throw InvalidDefinitionException.from(getGenerator(), msg, bean, null);
}
 
Example 4
Source File: SerializerProvider.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 2.9
 */
public <T> T reportBadDefinition(JavaType type, String msg, Throwable cause)
        throws JsonMappingException {
    InvalidDefinitionException e = InvalidDefinitionException.from(getGenerator(), msg, type);
    e.initCause(cause);
    throw e;
}
 
Example 5
Source File: SerializerProvider.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @since 2.9
 */
public <T> T reportBadDefinition(Class<?> raw, String msg, Throwable cause)
        throws JsonMappingException {
    InvalidDefinitionException e = InvalidDefinitionException.from(getGenerator(), msg, constructType(raw));
    e.initCause(cause);
    throw e;
}
 
Example 6
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method called to indicate problem in POJO (serialization) definitions or settings
 * regarding specific Java type, unrelated to actual JSON content to map.
 * Default behavior is to construct and throw a {@link JsonMappingException}.
 *
 * @since 2.9
 */
public <T> T reportBadTypeDefinition(BeanDescription bean,
        String msg, Object... msgArgs) throws JsonMappingException {
    msg = _format(msg, msgArgs);
    String beanDesc = ClassUtil.nameOf(bean.getBeanClass());
    msg = String.format("Invalid type definition for type %s: %s", beanDesc, msg);
    throw InvalidDefinitionException.from(_parser, msg, bean, null);
}
 
Example 7
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method called to indicate problem in POJO (serialization) definitions or settings
 * regarding specific property (of a type), unrelated to actual JSON content to map.
 * Default behavior is to construct and throw a {@link JsonMappingException}.
 *
 * @since 2.9
 */
public <T> T reportBadPropertyDefinition(BeanDescription bean, BeanPropertyDefinition prop,
        String msg, Object... msgArgs) throws JsonMappingException {
    msg = _format(msg, msgArgs);
    String propName = ClassUtil.nameOf(prop);
    String beanDesc = ClassUtil.nameOf(bean.getBeanClass());
    msg = String.format("Invalid definition for property %s (of type %s): %s",
            propName, beanDesc, msg);
    throw InvalidDefinitionException.from(_parser, msg, bean, prop);
}
 
Example 8
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Helper method for constructing instantiation exception for specified type,
 * to indicate problem with physically constructing instance of
 * specified class (missing constructor, exception from constructor)
 *<p>
 * Note that most of the time this method should NOT be called; instead,
 * {@link #handleInstantiationProblem} should be called which will call this method
 * if necessary.
 */
public JsonMappingException instantiationException(Class<?> instClass, Throwable cause) {
    // Most likely problem with Creator definition, right?
    JavaType type = constructType(instClass);
    String msg = String.format("Cannot construct instance of %s, problem: %s",
            ClassUtil.nameOf(instClass), cause.getMessage());
    InvalidDefinitionException e = InvalidDefinitionException.from(_parser, msg, type);
    e.initCause(cause);
    return e;
}
 
Example 9
Source File: SerializerProvider.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <T> T reportBadDefinition(JavaType type, String msg) throws JsonMappingException {
    throw InvalidDefinitionException.from(getGenerator(), msg, type);
}
 
Example 10
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <T> T reportBadDefinition(JavaType type, String msg) throws JsonMappingException {
    throw InvalidDefinitionException.from(_parser, msg, type);
}
 
Example 11
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Method that deserializer may call if it is called to do an update ("merge")
 * but deserializer operates on a non-mergeable type. Although this should
 * usually be caught earlier, sometimes it may only be caught during operation
 * and if so this is the method to call.
 * Note that if {@link MapperFeature#IGNORE_MERGE_FOR_UNMERGEABLE} is enabled,
 * this method will simply return null; otherwise {@link InvalidDefinitionException}
 * will be thrown.
 *
 * @since 2.9
 */
public <T> T reportBadMerge(JsonDeserializer<?> deser) throws JsonMappingException
{
    if (isEnabled(MapperFeature.IGNORE_MERGE_FOR_UNMERGEABLE)) {
        return null;
    }
    JavaType type = constructType(deser.handledType());
    String msg = String.format("Invalid configuration: values of type %s cannot be merged", type);
    throw InvalidDefinitionException.from(getParser(), msg, type);
}
 
Example 12
Source File: DeserializationContext.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Helper method for constructing instantiation exception for specified type,
 * to indicate that instantiation failed due to missing instantiator
 * (creator; constructor or factory method).
 *<p>
 * Note that most of the time this method should NOT be called; instead,
 * {@link #handleMissingInstantiator} should be called which will call this method
 * if necessary.
 */
public JsonMappingException instantiationException(Class<?> instClass, String msg0) {
    // Most likely problem with Creator definition, right?
    JavaType type = constructType(instClass);
    String msg = String.format("Cannot construct instance of %s: %s",
            ClassUtil.nameOf(instClass), msg0);
    return InvalidDefinitionException.from(_parser, msg, type);
}