|
1 | 1 | /* |
2 | | - * Copyright 2002-2015 the original author or authors. |
| 2 | + * Copyright 2002-2018 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
27 | 27 | import com.fasterxml.jackson.core.JsonEncoding; |
28 | 28 | import com.fasterxml.jackson.core.JsonGenerator; |
29 | 29 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 30 | +import com.fasterxml.jackson.databind.ObjectWriter; |
30 | 31 | import com.fasterxml.jackson.databind.SerializationFeature; |
31 | 32 | import com.fasterxml.jackson.databind.ser.FilterProvider; |
32 | 33 |
|
@@ -189,27 +190,26 @@ protected Object filterAndWrapModel(Map<String, Object> model, HttpServletReques |
189 | 190 | */ |
190 | 191 | protected void writeContent(OutputStream stream, Object object) throws IOException { |
191 | 192 | JsonGenerator generator = this.objectMapper.getFactory().createGenerator(stream, this.encoding); |
192 | | - |
193 | 193 | writePrefix(generator, object); |
| 194 | + |
| 195 | + Object value = object; |
194 | 196 | Class<?> serializationView = null; |
195 | 197 | FilterProvider filters = null; |
196 | | - Object value = object; |
197 | 198 |
|
198 | 199 | if (value instanceof MappingJacksonValue) { |
199 | 200 | MappingJacksonValue container = (MappingJacksonValue) value; |
200 | 201 | value = container.getValue(); |
201 | 202 | serializationView = container.getSerializationView(); |
202 | 203 | filters = container.getFilters(); |
203 | 204 | } |
204 | | - if (serializationView != null) { |
205 | | - this.objectMapper.writerWithView(serializationView).writeValue(generator, value); |
206 | | - } |
207 | | - else if (filters != null) { |
208 | | - this.objectMapper.writer(filters).writeValue(generator, value); |
209 | | - } |
210 | | - else { |
211 | | - this.objectMapper.writeValue(generator, value); |
| 205 | + |
| 206 | + ObjectWriter objectWriter = (serializationView != null ? |
| 207 | + this.objectMapper.writerWithView(serializationView) : this.objectMapper.writer()); |
| 208 | + if (filters != null) { |
| 209 | + objectWriter = objectWriter.with(filters); |
212 | 210 | } |
| 211 | + objectWriter.writeValue(generator, value); |
| 212 | + |
213 | 213 | writeSuffix(generator, object); |
214 | 214 | generator.flush(); |
215 | 215 | } |
|
0 commit comments