@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); } }
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));
getObjectMapper().readerWithView(jsonView).forType(javaType) : getObjectMapper().readerFor(javaType));
protected EP_CONFIG _configForReading(MAPPER mapper, Annotation[] annotations, Class<?> defaultView) { // ObjectReader r = _readerInjector.getAndClear(); ObjectReader r; if (defaultView != null) { r = mapper.readerWithView(defaultView); } else { r = mapper.reader(); } return _configForReading(r, annotations); }
@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); } }
@Provides @Named(READER_NAME) public ObjectReader objectReader(@Named(FrontObjectMapperFactory.MAPPER_NAME) final ObjectMapper mapper) { return mapper.readerWithView(Views.Transient.class); } }
protected EP_CONFIG _configForReading(MAPPER mapper, Annotation[] annotations, Class<?> defaultView) { // ObjectReader r = _readerInjector.getAndClear(); ObjectReader r; if (defaultView != null) { r = mapper.readerWithView(defaultView); } else { r = mapper.reader(); } return _configForReading(r, annotations); }
protected EP_CONFIG _configForReading(MAPPER mapper, Annotation[] annotations, Class<?> defaultView) { // ObjectReader r = _readerInjector.getAndClear(); ObjectReader r; if (defaultView != null) { r = mapper.readerWithView(defaultView); } else { r = mapper.reader(); } return _configForReading(r, annotations); }
protected EP_CONFIG _configForReading(MAPPER mapper, Annotation[] annotations, Class<?> defaultView) { // ObjectReader r = _readerInjector.getAndClear(); ObjectReader r; if (defaultView != null) { r = mapper.readerWithView(defaultView); } else { r = mapper.reader(); } return _configForReading(r, annotations); }
@Provides @Named(READER_NAME) public ObjectReader objectReader(@Named(FrontObjectMapperFactory.MAPPER_NAME) final ObjectMapper mapper) { return mapper.readerWithView(Views.Transient.class); } }
protected EP_CONFIG _configForReading(MAPPER mapper, Annotation[] annotations, Class<?> defaultView) { // ObjectReader r = _readerInjector.getAndClear(); ObjectReader r; if (defaultView != null) { r = mapper.readerWithView(defaultView); } else { r = mapper.reader(); } return _configForReading(r, annotations); }
protected EP_CONFIG _configForReading(MAPPER mapper, Annotation[] annotations, Class<?> defaultView) { // ObjectReader r = _readerInjector.getAndClear(); ObjectReader r; if (defaultView != null) { r = mapper.readerWithView(defaultView); } else { r = mapper.reader(); } return _configForReading(r, annotations); }
@SuppressWarnings("deprecation") private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) { try { if (inputMessage instanceof MappingJacksonInputMessage) { Class<?> deserializationView = ((MappingJacksonInputMessage) inputMessage).getDeserializationView(); if (deserializationView != null) { return this.objectMapper.readerWithView(deserializationView).withType(javaType) .readValue(inputMessage.getBody()); } } return this.objectMapper.readValue(inputMessage.getBody(), javaType); } catch (IOException ex) { throw new HttpMessageNotReadableException("Could not read document: " + ex.getMessage(), ex); } }
/** * Convert a DBObject, normally a query result to the object type for this * collection using the Jackson ObjectMapper for this collection. * * @param dbObject The DBObject to convert * @return A converted instance of the object type of this class. * @throws MongoException */ public T convertFromDbObject(DBObject dbObject) throws MongoException { if (dbObject == null) { return null; } if (dbObject instanceof JacksonDBObject) { return (T) ((JacksonDBObject) dbObject).getObject(); } try { return (T) objectMapper.readerWithView(view).readValue(new BsonObjectTraversingParser( this, dbObject, objectMapper), type); } catch (JsonMappingException e) { throw new MongoJsonMappingException(e); } catch (IOException e) { // This shouldn't happen throw new MongoException( "Unknown error occurred converting BSON to object", e); } }
/** * Convert a DBObject into a given class, using the Jackson ObjectMapper * for this collection. * * @param dbObject The DBObject to convert * @param clazz The class into which we are converting. * @return An instance of the requested class mapped from the DBObject. * @throws MongoException */ public <S> S convertFromDbObject(DBObject dbObject, Class<S> clazz) throws MongoException { if (dbObject == null) { return null; } if (dbObject instanceof JacksonDBObject) { return (S) ((JacksonDBObject) dbObject).getObject(); } try { return objectMapper.readerWithView(view).readValue(new BsonObjectTraversingParser(this, dbObject, objectMapper), clazz); } catch (JsonMappingException e) { throw new MongoJsonMappingException(e); } catch (IOException e) { // This shouldn't happen throw new MongoException( "Unknown error occurred converting BSON to object", e); } }
private Flux<Object> decodeInternal(Flux<TokenBuffer> tokens, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { Assert.notNull(tokens, "'tokens' must not be null"); Assert.notNull(elementType, "'elementType' must not be null"); MethodParameter param = getParameter(elementType); Class<?> contextClass = (param != null ? param.getContainingClass() : null); JavaType javaType = getJavaType(elementType.getType(), contextClass); Class<?> jsonView = (hints != null ? (Class<?>) hints.get(Jackson2CodecSupport.JSON_VIEW_HINT) : null); ObjectReader reader = (jsonView != null ? getObjectMapper().readerWithView(jsonView).forType(javaType) : getObjectMapper().readerFor(javaType)); return tokens.map(tokenBuffer -> { try { return reader.readValue(tokenBuffer.asParser(getObjectMapper())); } catch (InvalidDefinitionException ex) { throw new CodecException("Type definition error: " + ex.getType(), ex); } catch (JsonProcessingException ex) { throw new DecodingException("JSON decoding error: " + ex.getOriginalMessage(), ex); } catch (IOException ex) { throw new DecodingException("I/O error while parsing input stream", ex); } }); }
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); } }