/** * @deprecated since 2.5 Use {@link #forType(JavaType)} instead */ @Deprecated public ObjectReader withType(JavaType valueType) { return forType(valueType); }
/** * Type-safe overloaded method, basically alias for {@link #readValue(JsonParser, ResolvedType)}. *<p> * NOTE: this method never tries to auto-detect format, since actual * (data-format specific) parser is given. */ @SuppressWarnings("unchecked") public <T> T readValue(JsonParser p, JavaType valueType) throws IOException { return (T) forType(valueType).readValue(p); }
/** * Convenience method that binds content read using given parser, using * configuration of this reader, except that expected value type * is specified with the call (instead of currently configured root type). * Value return is either newly constructed, or root value that * was specified with {@link #withValueToUpdate(Object)}. *<p> * NOTE: this method never tries to auto-detect format, since actual * (data-format specific) parser is given. */ @Override @SuppressWarnings("unchecked") public <T> T readValue(JsonParser p, ResolvedType valueType) throws IOException { return (T) forType((JavaType)valueType).readValue(p); }
/** * Convenience method that binds content read using given parser, using * configuration of this reader, except that expected value type * is specified with the call (instead of currently configured root type). * Value return is either newly constructed, or root value that * was specified with {@link #withValueToUpdate(Object)}. *<p> * NOTE: this method never tries to auto-detect format, since actual * (data-format specific) parser is given. */ @SuppressWarnings("unchecked") @Override public <T> T readValue(JsonParser p, Class<T> valueType) throws IOException { return (T) forType(valueType).readValue(p); }
/** * Convenience method that binds content read using given parser, using * configuration of this reader, except that expected value type * is specified with the call (instead of currently configured root type). * Value return is either newly constructed, or root value that * was specified with {@link #withValueToUpdate(Object)}. *<p> * NOTE: this method never tries to auto-detect format, since actual * (data-format specific) parser is given. */ @SuppressWarnings("unchecked") @Override public <T> T readValue(JsonParser p, TypeReference<?> valueTypeRef) throws IOException { return (T) forType(valueTypeRef).readValue(p); }
/** * @deprecated since 2.5 Use {@link #forType(Class)} instead */ @Deprecated public ObjectReader withType(java.lang.reflect.Type valueType) { return forType(_config.getTypeFactory().constructType(valueType)); }
/** * @deprecated since 2.5 Use {@link #forType(Class)} instead */ @Deprecated public ObjectReader withType(Class<?> valueType) { return forType(_config.constructType(valueType)); }
public DataFormatReaders withType(JavaType type) { final int len = _readers.length; ObjectReader[] r = new ObjectReader[len]; for (int i = 0; i < len; ++i) { r[i] = _readers[i].forType(type); } return new DataFormatReaders(r, _optimalMatch, _minimalMatch, _maxInputLookahead); }
/** * Method for constructing a new reader instance that is configured * to data bind into specified type. *<p> * Note that the method does NOT change state of this reader, but * rather construct and returns a newly configured instance. * * @since 2.5 */ public ObjectReader forType(Class<?> valueType) { return forType(_config.constructType(valueType)); }
/** * @deprecated since 2.5 Use {@link #forType(TypeReference)} instead */ @Deprecated public ObjectReader withType(TypeReference<?> valueTypeRef) { return forType(_config.getTypeFactory().constructType(valueTypeRef.getType())); }
/** * Convenience method that is equivalent to: *<pre> * withType(valueType).readValues(p); *</pre> *<p> * Method reads a sequence of Objects from parser stream. * Sequence can be either root-level "unwrapped" sequence (without surrounding * JSON array), or a sequence contained in a JSON Array. * In either case {@link JsonParser} <b>MUST</b> point to the first token of * the first element, OR not point to any token (in which case it is advanced * to the next token). This means, specifically, that for wrapped sequences, * parser MUST NOT point to the surrounding <code>START_ARRAY</code> (one that * contains values to read) but rather to the token following it which is the first * token of the first value to read. *<p> * NOTE: this method never tries to auto-detect format, since actual * (data-format specific) parser is given. */ public <T> Iterator<T> readValues(JsonParser p, JavaType valueType) throws IOException { return forType(valueType).readValues(p); }
/** * Convenience method that is equivalent to: *<pre> * withType(valueType).readValues(p); *</pre> *<p> * Method reads a sequence of Objects from parser stream. * Sequence can be either root-level "unwrapped" sequence (without surrounding * JSON array), or a sequence contained in a JSON Array. * In either case {@link JsonParser} <b>MUST</b> point to the first token of * the first element, OR not point to any token (in which case it is advanced * to the next token). This means, specifically, that for wrapped sequences, * parser MUST NOT point to the surrounding <code>START_ARRAY</code> (one that * contains values to read) but rather to the token following it which is the first * token of the first value to read. *<p> * NOTE: this method never tries to auto-detect format, since actual * (data-format specific) parser is given. */ @Override public <T> Iterator<T> readValues(JsonParser p, Class<T> valueType) throws IOException { return forType(valueType).readValues(p); }
/** * Convenience method that is equivalent to: *<pre> * withType(valueTypeRef).readValues(p); *</pre> *<p> * Method reads a sequence of Objects from parser stream. * Sequence can be either root-level "unwrapped" sequence (without surrounding * JSON array), or a sequence contained in a JSON Array. * In either case {@link JsonParser} <b>MUST</b> point to the first token of * the first element, OR not point to any token (in which case it is advanced * to the next token). This means, specifically, that for wrapped sequences, * parser MUST NOT point to the surrounding <code>START_ARRAY</code> (one that * contains values to read) but rather to the token following it which is the first * token of the first value to read. *<p> * NOTE: this method never tries to auto-detect format, since actual * (data-format specific) parser is given. */ @Override public <T> Iterator<T> readValues(JsonParser p, TypeReference<?> valueTypeRef) throws IOException { return forType(valueTypeRef).readValues(p); }
/** * Method for constructing a new reader instance that is configured * to data bind into specified type. *<p> * Note that the method does NOT change state of this reader, but * rather construct and returns a newly configured instance. * * @since 2.5 */ public ObjectReader forType(TypeReference<?> valueTypeRef) { return forType(_config.getTypeFactory().constructType(valueTypeRef.getType())); }
@Override @Nullable protected Object convertFromInternal(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) { JavaType javaType = getJavaType(targetClass, conversionHint); Object payload = message.getPayload(); Class<?> view = getSerializationView(conversionHint); // Note: in the view case, calling withType instead of forType for compatibility with Jackson <2.5 try { if (payload instanceof byte[]) { if (view != null) { return this.objectMapper.readerWithView(view).forType(javaType).readValue((byte[]) payload); } else { return this.objectMapper.readValue((byte[]) payload, javaType); } } else { if (view != null) { return this.objectMapper.readerWithView(view).forType(javaType).readValue(payload.toString()); } else { return this.objectMapper.readValue(payload.toString(), javaType); } } } catch (IOException ex) { throw new MessageConversionException(message, "Could not read JSON: " + ex.getMessage(), ex); } }
public Consumer<DataBuffer> pojoConsumer(Pojo expected) { return dataBuffer -> { try { Pojo actual = this.mapper.reader().forType(Pojo.class) .readValue(DataBufferTestUtils.dumpBytes(dataBuffer)); assertEquals(expected, actual); release(dataBuffer); } catch (IOException ex) { throw new UncheckedIOException(ex); } }; }
private <T> Consumer<DataBuffer> expect(T expected, Class<T> expectedType) { return dataBuffer -> { try { Object actual = this.mapper.reader().forType(expectedType) .readValue(dataBuffer.asInputStream()); assertEquals(expected, actual); } catch (IOException e) { throw new UncheckedIOException(e); } finally { release(dataBuffer); } }; }
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) throws IOException { try { if (inputMessage instanceof MappingJacksonInputMessage) { Class<?> deserializationView = ((MappingJacksonInputMessage) inputMessage).getDeserializationView(); if (deserializationView != null) { return this.objectMapper.readerWithView(deserializationView).forType(javaType). readValue(inputMessage.getBody()); } } return this.objectMapper.readValue(inputMessage.getBody(), javaType); } catch (InvalidDefinitionException ex) { throw new HttpMessageConversionException("Type definition error: " + ex.getType(), ex); } catch (JsonProcessingException ex) { throw new HttpMessageNotReadableException("JSON parse error: " + ex.getOriginalMessage(), ex, inputMessage); } }
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) throws IOException { try { if (inputMessage instanceof MappingJacksonInputMessage) { Class<?> deserializationView = ((MappingJacksonInputMessage) inputMessage).getDeserializationView(); if (deserializationView != null) { return this.objectMapper.readerWithView(deserializationView).forType(javaType). readValue(inputMessage.getBody()); } } return this.objectMapper.readValue(inputMessage.getBody(), javaType); } catch (InvalidDefinitionException ex) { throw new HttpMessageConversionException("Type definition error: " + ex.getType(), ex); } catch (JsonProcessingException ex) { throw new HttpMessageNotReadableException("JSON parse error: " + ex.getOriginalMessage(), ex, inputMessage); } }
getObjectMapper().readerWithView(jsonView).forType(javaType) : getObjectMapper().readerFor(javaType));