com.fasterxml.jackson.databind.exc.InvalidFormatException.from()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中com.fasterxml.jackson.databind.exc.InvalidFormatException.from()方法的一些代码示例,展示了InvalidFormatException.from()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。InvalidFormatException.from()方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.exc.InvalidFormatException
类名称:InvalidFormatException
方法名:from

InvalidFormatException.from介绍

暂无

代码示例

代码示例来源:origin: redisson/redisson

/**
 * Helper method for constructing exception to indicate that input JSON
 * Number was not suitable for deserializing into given target type.
 * Note that most of the time this method should NOT be called; instead,
 * {@link #handleWeirdNumberValue} should be called which will call this method
 * if necessary.
 */
public JsonMappingException weirdNumberException(Number value, Class<?> instClass,
    String msg) {
  return InvalidFormatException.from(_parser,
      String.format("Cannot deserialize value of type %s from number %s: %s",
          ClassUtil.nameOf(instClass), String.valueOf(value), msg),
      value, instClass);
}

代码示例来源:origin: redisson/redisson

/**
 * Helper method for constructing exception to indicate that given JSON
 * Object field name was not in format to be able to deserialize specified
 * key type.
 * Note that most of the time this method should NOT be called; instead,
 * {@link #handleWeirdKey} should be called which will call this method
 * if necessary.
 */
public JsonMappingException weirdKeyException(Class<?> keyClass, String keyValue,
    String msg) {
  return InvalidFormatException.from(_parser,
      String.format("Cannot deserialize Map key of type %s from String %s: %s",
          ClassUtil.nameOf(keyClass), _quotedString(keyValue), msg),
      keyValue, keyClass);
}

代码示例来源:origin: redisson/redisson

/**
   * Helper method for constructing exception to indicate that input JSON
   * token of type "native value" (see {@link JsonToken#VALUE_EMBEDDED_OBJECT})
   * is of incompatible type (and there is no delegating creator or such to use)
   * and can not be used to construct value of specified type (usually POJO).
   * Note that most of the time this method should NOT be called; instead,
   * {@link #handleWeirdNativeValue} should be called which will call this method
   *
   * @since 2.9
   */
  public JsonMappingException weirdNativeValueException(Object value, Class<?> instClass)
  {
    return InvalidFormatException.from(_parser, String.format(
"Cannot deserialize value of type %s from native value (`JsonToken.VALUE_EMBEDDED_OBJECT`) of type %s: incompatible types",
      ClassUtil.nameOf(instClass), ClassUtil.classNameOf(value)),
        value, instClass);
  }

代码示例来源:origin: redisson/redisson

/**
   * Method for accessing textual contents assuming they were
   * base64 encoded; if so, they are decoded and resulting binary
   * data is returned.
   */
  @SuppressWarnings("resource")
  public byte[] getBinaryValue(Base64Variant b64variant) throws IOException
  {
    final String str = _value.trim();
    ByteArrayBuilder builder = new ByteArrayBuilder(4 + ((str.length() * 3) << 2));
    try {
      b64variant.decode(str, builder);
    } catch (IllegalArgumentException e) {
      throw InvalidFormatException.from(null,
          String.format(
"Cannot access contents of TextNode as binary due to broken Base64 encoding: %s",
e.getMessage()),
          str, byte[].class);
    }
    return builder.toByteArray();
  }

代码示例来源:origin: redisson/redisson

/**
 * Helper method for constructing exception to indicate that input JSON
 * String was not suitable for deserializing into given target type.
 * Note that most of the time this method should NOT be called; instead,
 * {@link #handleWeirdStringValue} should be called which will call this method
 * if necessary.
 * 
 * @param value String value from input being deserialized
 * @param instClass Type that String should be deserialized into
 * @param msg Message that describes specific problem
 * 
 * @since 2.1
 */
public JsonMappingException weirdStringException(String value, Class<?> instClass,
    String msg) {
  return InvalidFormatException.from(_parser,
      String.format("Cannot deserialize value of type %s from String %s: %s",
          ClassUtil.nameOf(instClass), _quotedString(value), msg),
      value, instClass);
}

代码示例来源:origin: redisson/redisson

private UUID _fromBytes(byte[] bytes, DeserializationContext ctxt) throws JsonMappingException {
  if (bytes.length != 16) {
    throw InvalidFormatException.from(ctxt.getParser(),
        "Can only construct UUIDs from byte[16]; got "+bytes.length+" bytes",
        bytes, handledType());
  }
  return new UUID(_long(bytes, 0), _long(bytes, 8));
}

代码示例来源:origin: Nextdoor/bender

/**
 * Helper method for constructing exception to indicate that input JSON
 * Number was not suitable for deserializing into given target type.
 * Note that most of the time this method should NOT be called; instead,
 * {@link #handleWeirdNumberValue} should be called which will call this method
 * if necessary.
 */
public JsonMappingException weirdNumberException(Number value, Class<?> instClass,
    String msg) {
  return InvalidFormatException.from(_parser,
      String.format("Can not deserialize value of type %s from number %s: %s",
          instClass.getName(), String.valueOf(value), msg),
      value, instClass);
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

/**
 * Helper method for constructing exception to indicate that input JSON
 * Number was not suitable for deserializing into given target type.
 */
public JsonMappingException weirdNumberException(Number value, Class<?> instClass, String msg) {
  return InvalidFormatException.from(_parser,
      "Can not construct instance of "+instClass.getName()+" from number value ("+_valueDesc()+"): "+msg,
      null, instClass);
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

/**
 * Helper method for constructing exception to indicate that given JSON
 * Object field name was not in format to be able to deserialize specified
 * key type.
 */
public JsonMappingException weirdKeyException(Class<?> keyClass, String keyValue, String msg) {
  return InvalidFormatException.from(_parser,
      "Can not construct Map key of type "+keyClass.getName()+" from String \""+_desc(keyValue)+"\": "+msg,
      keyValue, keyClass);
}

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

/**
 * Helper method for constructing exception to indicate that input JSON
 * Number was not suitable for deserializing into given target type.
 */
public JsonMappingException weirdNumberException(Number value, Class<?> instClass, String msg) {
  return InvalidFormatException.from(_parser,
      "Can not construct instance of "+instClass.getName()+" from number value ("+_valueDesc()+"): "+msg,
      null, instClass);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

/**
 * Helper method for constructing exception to indicate that input JSON
 * Number was not suitable for deserializing into given target type.
 */
public JsonMappingException weirdNumberException(Number value, Class<?> instClass, String msg) {
  return InvalidFormatException.from(_parser,
      "Can not construct instance of "+instClass.getName()+" from number value ("+_valueDesc()+"): "+msg,
      null, instClass);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

/**
 * Helper method for constructing exception to indicate that given JSON
 * Object field name was not in format to be able to deserialize specified
 * key type.
 */
public JsonMappingException weirdKeyException(Class<?> keyClass, String keyValue, String msg)
{
  return InvalidFormatException.from(_parser,
      "Can not construct Map key of type "+keyClass.getName()+" from String \""+_desc(keyValue)+"\": "+msg,
      keyValue, keyClass);
}

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

/**
 * Helper method for constructing exception to indicate that given JSON
 * Object field name was not in format to be able to deserialize specified
 * key type.
 */
public JsonMappingException weirdKeyException(Class<?> keyClass, String keyValue, String msg) {
  return InvalidFormatException.from(_parser,
      "Can not construct Map key of type "+keyClass.getName()+" from String \""+_desc(keyValue)+"\": "+msg,
      keyValue, keyClass);
}

代码示例来源:origin: Nextdoor/bender

/**
 * Helper method for constructing exception to indicate that given JSON
 * Object field name was not in format to be able to deserialize specified
 * key type.
 * Note that most of the time this method should NOT be called; instead,
 * {@link #handleWeirdKey} should be called which will call this method
 * if necessary.
 */
public JsonMappingException weirdKeyException(Class<?> keyClass, String keyValue,
    String msg) {
  return InvalidFormatException.from(_parser,
      String.format("Can not deserialize Map key of type %s from String %s: %s",
          keyClass.getName(), _quotedString(keyValue), msg),
      keyValue, keyClass);
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

/**
 * Method that will construct an exception suitable for throwing when
 * some String values are acceptable, but the one encountered is not.
 * 
 * @param value String value from input being deserialized
 * @param instClass Type that String should be deserialized into
 * @param msg Message that describes specific problem
 * 
 * @since 2.1
 */
public JsonMappingException weirdStringException(String value, Class<?> instClass, String msg) {
  return InvalidFormatException.from(_parser,
      "Can not construct instance of "+instClass.getName()+" from String value '"+_valueDesc()+"': "+msg,
      value, instClass);
}

代码示例来源:origin: com.jwebmp.jackson.core/jackson-databind

/**
 * Helper method for constructing exception to indicate that input JSON
 * Number was not suitable for deserializing into given target type.
 * Note that most of the time this method should NOT be called; instead,
 * {@link #handleWeirdNumberValue} should be called which will call this method
 * if necessary.
 */
public JsonMappingException weirdNumberException(Number value, Class<?> instClass,
    String msg) {
  return InvalidFormatException.from(_parser,
      String.format("Cannot deserialize value of type %s from number %s: %s",
          ClassUtil.nameOf(instClass), String.valueOf(value), msg),
      value, instClass);
}

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

/**
 * Method that will construct an exception suitable for throwing when
 * some String values are acceptable, but the one encountered is not.
 * 
 * @param value String value from input being deserialized
 * @param instClass Type that String should be deserialized into
 * @param msg Message that describes specific problem
 * 
 * @since 2.1
 */
public JsonMappingException weirdStringException(String value, Class<?> instClass, String msg) {
  return InvalidFormatException.from(_parser,
      "Can not construct instance of "+instClass.getName()+" from String value '"+_valueDesc()+"': "+msg,
      value, instClass);
}

代码示例来源:origin: com.jwebmp.jackson.core/jackson-databind

/**
 * Helper method for constructing exception to indicate that given JSON
 * Object field name was not in format to be able to deserialize specified
 * key type.
 * Note that most of the time this method should NOT be called; instead,
 * {@link #handleWeirdKey} should be called which will call this method
 * if necessary.
 */
public JsonMappingException weirdKeyException(Class<?> keyClass, String keyValue,
    String msg) {
  return InvalidFormatException.from(_parser,
      String.format("Cannot deserialize Map key of type %s from String %s: %s",
          ClassUtil.nameOf(keyClass), _quotedString(keyValue), msg),
      keyValue, keyClass);
}

代码示例来源:origin: Nextdoor/bender

private UUID _fromBytes(byte[] bytes, DeserializationContext ctxt) throws JsonMappingException {
  if (bytes.length != 16) {
    throw InvalidFormatException.from(ctxt.getParser(),
        "Can only construct UUIDs from byte[16]; got "+bytes.length+" bytes",
        bytes, handledType());
  }
  return new UUID(_long(bytes, 0), _long(bytes, 8));
}

代码示例来源:origin: com.jwebmp.jackson.core/jackson-databind

private UUID _fromBytes(byte[] bytes, DeserializationContext ctxt) throws JsonMappingException {
  if (bytes.length != 16) {
    throw InvalidFormatException.from(ctxt.getParser(),
        "Can only construct UUIDs from byte[16]; got "+bytes.length+" bytes",
        bytes, handledType());
  }
  return new UUID(_long(bytes, 0), _long(bytes, 8));
}

相关文章