/** * Factory method for constructing {@link ObjectReader} that will * use specified injectable values. * * @param injectableValues Injectable values to use * * @since 1.9 */ public ObjectReader reader(InjectableValues injectableValues) { return new ObjectReader(this, copyDeserializationConfig(), null, null, null, injectableValues); }
/** * Factory method for constructing {@link ObjectReader} that will * read or update instances of specified type * * @since 1.6 */ public ObjectReader reader(JavaType type) { return new ObjectReader(this, copyDeserializationConfig(), type, null, null, _injectableValues); }
/** * Method to deserialize JSON content into a Java type, reference * to which is passed as argument. Type is passed using * Jackson specific type; instance of which can be constructed using * {@link TypeFactory}. */ @Override @SuppressWarnings("unchecked") public <T> T readValue(JsonParser jp, JavaType valueType) throws IOException, JsonParseException, JsonMappingException { return (T) _readValue(copyDeserializationConfig(), jp, valueType); }
/** * Method that can be called to check whether mapper thinks * it could deserialize an Object of given type. * Check is done * by checking whether a deserializer can be found for the type. * * @return True if mapper can find a serializer for instances of * given class (potentially serializable), false otherwise (not * serializable) */ public boolean canDeserialize(JavaType type) { return _deserializerProvider.hasValueDeserializerFor(copyDeserializationConfig(), type); }
/** * Factory method for constructing {@link ObjectReader} that will * pass specific schema object to {@link JsonParser} used for * reading content. * * @param schema Schema to pass to parser * * @since 1.8 */ public ObjectReader reader(FormatSchema schema) { return new ObjectReader(this, copyDeserializationConfig(), null, null, schema, _injectableValues); }
/** * Factory method for constructing {@link ObjectReader} with * default settings. Note that the resulting instance is NOT usable as is, * without defining expected value type. * * @since 1.6 */ public ObjectReader reader() { return new ObjectReader(this, copyDeserializationConfig()) .withInjectableValues(_injectableValues); }
/** * Factory method for constructing {@link ObjectReader} that will * use specified {@link JsonNodeFactory} for constructing JSON trees. * * @since 1.6 */ public ObjectReader reader(JsonNodeFactory f) { return new ObjectReader(this, copyDeserializationConfig()).withNodeFactory(f); }
/** * Method to deserialize JSON content into a Java type, reference * to which is passed as argument. Type is passed using so-called * "super type token" (see ) * and specifically needs to be used if the root type is a * parameterized (generic) container type. */ @Override @SuppressWarnings("unchecked") public <T> T readValue(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonParseException, JsonMappingException { return (T) _readValue(copyDeserializationConfig(), jp, _typeFactory.constructType(valueTypeRef)); }
/** * Factory method for constructing {@link ObjectReader} that will * update given Object (usually Bean, but can be a Collection or Map * as well, but NOT an array) with JSON data. Deserialization occurs * normally except that the root-level value in JSON is not used for * instantiating a new object; instead give updateable object is used * as root. * Runtime type of value object is used for locating deserializer, * unless overridden by other factory methods of {@link ObjectReader} * * @since 1.9 */ public ObjectReader readerForUpdating(Object valueToUpdate) { JavaType t = _typeFactory.constructType(valueToUpdate.getClass()); return new ObjectReader(this, copyDeserializationConfig(), t, valueToUpdate, null, _injectableValues); }
/** * Convenience method for converting results from given JSON tree into given * value type. Basically short-cut for: *<pre> * mapper.readValue(mapper.treeAsTokens(root), valueType); *</pre> * * @since 1.6 */ @SuppressWarnings("unchecked") public <T> T readValue(JsonNode root, JavaType valueType) throws IOException, JsonParseException, JsonMappingException { return (T) _readValue(copyDeserializationConfig(), treeAsTokens(root), valueType); }
/** * Method to deserialize JSON content into a non-container * type (it can be an array type, however): typically a bean, array * or a wrapper type (like {@link java.lang.Boolean}). *<p> * Note: this method should NOT be used if the result type is a * container ({@link java.util.Collection} or {@link java.util.Map}. * The reason is that due to type erasure, key and value types * can not be introspected when using this method. */ @Override @SuppressWarnings("unchecked") public <T> T readValue(JsonParser jp, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException { // !!! TODO // _setupClassLoaderForDeserialization(valueType); return (T) _readValue(copyDeserializationConfig(), jp, _typeFactory.constructType(valueType)); }
/** * Convenience method for converting results from given JSON tree into given * value type. Basically short-cut for: *<pre> * mapper.readValue(mapper.treeAsTokens(root), valueType); *</pre> * * @since 1.6 */ @SuppressWarnings({ "unchecked", "rawtypes" }) public <T> T readValue(JsonNode root, TypeReference valueTypeRef) throws IOException, JsonParseException, JsonMappingException { return (T) _readValue(copyDeserializationConfig(), treeAsTokens(root), _typeFactory.constructType(valueTypeRef)); }
/** * Convenience method for converting results from given JSON tree into given * value type. Basically short-cut for: *<pre> * mapper.readValue(mapper.treeAsTokens(root), valueType); *</pre> * * @since 1.6 */ @SuppressWarnings("unchecked") public <T> T readValue(JsonNode root, Class<T> valueType) throws IOException, JsonParseException, JsonMappingException { // !!! TODO // _setupClassLoaderForDeserialization(valueType); return (T) _readValue(copyDeserializationConfig(), treeAsTokens(root), _typeFactory.constructType(valueType)); }
/** * Constructor used by {@link ObjectMapper} for initial instantiation */ protected BackportedObjectReader(ObjectMapper mapper, JavaType valueType, Object valueToUpdate) { _rootDeserializers = ReflectionUtils.getField(ROOT_DESERIALIZERS, mapper); _provider = mapper.getDeserializerProvider(); _jsonFactory = mapper.getJsonFactory(); // must make a copy at this point, to prevent further changes from trickling down _config = mapper.copyDeserializationConfig(); _valueType = valueType; _valueToUpdate = valueToUpdate; if (valueToUpdate != null && valueType.isArrayType()) { throw new IllegalArgumentException("Can not update an array value"); } }
/** * Method for reading sequence of Objects from parser stream. *<p> * Note that {@link ObjectReader} has more complete set of variants. * * @since 1.8 */ @Override public <T> MappingIterator<T> readValues(JsonParser jp, JavaType valueType) throws IOException, JsonProcessingException { DeserializationConfig config = copyDeserializationConfig(); DeserializationContext ctxt = _createDeserializationContext(jp, config); JsonDeserializer<?> deser = _findRootDeserializer(config, valueType); // false -> do NOT close JsonParser (since caller passed it) return new MappingIterator<T>(valueType, jp, ctxt, deser, false, null); }
/** * Customized {@link TypeResolverBuilder} that provides type resolver builders * used with so-called "default typing" * (see {@link ObjectMapper#enableDefaultTyping()} for details). *<p> * Type resolver construction is based on configuration: implementation takes care * of only providing builders in cases where type information should be applied. * This is important since build calls may be sent for any and all types, and * type information should NOT be applied to all of them. */ public static class DefaultTypeResolverBuilder extends StdTypeResolverBuilder { /** * Definition of what types is this default typer valid for. */ protected final DefaultTyping _appliesFor; public DefaultTypeResolverBuilder(DefaultTyping t) { _appliesFor = t; } @Override public TypeDeserializer buildTypeDeserializer(DeserializationConfig config, JavaType baseType, Collection<NamedType> subtypes, BeanProperty property) { return useForType(baseType) ? super.buildTypeDeserializer(config, baseType, subtypes, property) : null; } @Override
result = null; } else { DeserializationConfig cfg = copyDeserializationConfig(); DeserializationContext ctxt = _createDeserializationContext(jp, cfg); JsonDeserializer<Object> deser = _findRootDeserializer(cfg, valueType);
/** * Factory method for constructing {@link ObjectReader} that will * use specified injectable values. * * @param injectableValues Injectable values to use * * @since 1.9 */ public ObjectReader reader(InjectableValues injectableValues) { return new ObjectReader(this, copyDeserializationConfig(), null, null, null, injectableValues); }
/** * Factory method for constructing {@link ObjectReader} that will * read or update instances of specified type * * @since 1.6 */ public ObjectReader reader(JavaType type) { return new ObjectReader(this, copyDeserializationConfig(), type, null, null, _injectableValues); }
/** * Factory method for constructing {@link ObjectReader} with * default settings. Note that the resulting instance is NOT usable as is, * without defining expected value type. * * @since 1.6 */ public ObjectReader reader() { return new ObjectReader(this, copyDeserializationConfig()) .withInjectableValues(_injectableValues); }