Java Code Examples for com.fasterxml.jackson.databind.exc.InvalidFormatException#from()
The following examples show how to use
com.fasterxml.jackson.databind.exc.InvalidFormatException#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: TextNode.java From lams with GNU General Public License v2.0 | 6 votes |
/** * 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(); }
Example 2
Source File: StateOptions.java From java-sdk with MIT License | 5 votes |
@Override public Duration deserialize( JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { String durationStr = jsonParser.readValueAs(String.class); Duration duration = null; if (durationStr != null && !durationStr.trim().isEmpty()) { try { duration = DurationUtils.convertDurationFromDaprFormat(durationStr); } catch (Exception ex) { throw InvalidFormatException.from(jsonParser, "Unable to parse duration.", ex); } } return duration; }
Example 3
Source File: UUIDDeserializer.java From lams with GNU General Public License v2.0 | 5 votes |
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)); }
Example 4
Source File: DeserializationContext.java From lams with GNU General Public License v2.0 | 5 votes |
/** * 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); }
Example 5
Source File: AvroGenericRecordMapper.java From divolte-collector with Apache License 2.0 | 5 votes |
private static InvalidFormatException unknownEnumValueException(final JsonParser parser, final Schema targetSchema, final String symbol) { return InvalidFormatException.from(parser, "Symbol " + symbol + " is not valid for enumeration " + targetSchema.getName(), symbol, null); }
Example 6
Source File: DurationDeserializer.java From divolte-collector with Apache License 2.0 | 5 votes |
@Override public Duration deserialize(final JsonParser p, final DeserializationContext ctx) throws IOException { if (VALUE_STRING != p.getCurrentToken()) { ctx.reportWrongTokenException(this, VALUE_STRING, "Expected string value for Duration mapping."); } long result; try { result = parse(p.getText()); } catch(final DurationFormatException e) { throw InvalidFormatException.from(p, e.getMessage(), e); } return Duration.ofNanos(result); }
Example 7
Source File: DeserializationContext.java From lams with GNU General Public License v2.0 | 3 votes |
/** * 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); }
Example 8
Source File: DeserializationContext.java From lams with GNU General Public License v2.0 | 3 votes |
/** * 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); }
Example 9
Source File: DeserializationContext.java From lams with GNU General Public License v2.0 | 3 votes |
/** * 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); }