Comments (3)
Thanks for the info. I think I did not fall into this problem as I use an adapted version of the Readme. If you like you could give it a try and if that works for you too I will update the Readme?
/**
* A specific {@link MappingJackson2HttpMessageConverter} that configures the given {@link ObjectMapper} with the
* {@link AntPathFilterMixin}. This is needed only if we need multiple ObjectMappers.
*
* @author mfrey
*
*/
public class AntPathFilterJackson2HttpMessageConverter extends MappingJackson2HttpMessageConverter {
public AntPathFilterJackson2HttpMessageConverter(final ObjectMapper objectMapper) {
super(objectMapper);
ObjectMapper copy = objectMapper.copy();
copy.addMixIn(Object.class, AntPathFilterMixin.class);
setObjectMapper(copy);
}
@Override
public boolean canWrite(final Class<?> clazz, final MediaType mediaType) {
return AntPathFilterMappingJacksonValue.class.isAssignableFrom(clazz);
}
}
@Configuration
public class WebConfig extends DelegatingWebMvcConfiguration {
@Override
public void configureMessageConverters(final List<HttpMessageConverter<?>> messageConverters) {
// Add a MappingJackson2HttpMessageConverter so that
// objectMapper.writeFiltered
// is using the objectMapper configured with the needed Mixin
messageConverters.add(new AntPathFilterJackson2HttpMessageConverter(objectMapper));
//
addDefaultHttpMessageConverters(messageConverters);
super.configureMessageConverters(messageConverters);
}
}
@RequestMapping(value = "", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public AntPathFilterMappingJacksonValue list() throws JsonProcessingException {
List<User> allUsers = userService.allUsers();
return new AntPathFilterMappingJacksonValue(allUsers, "id", "login", "firstName", "lastName", "email",
"currentRoles", "managedScopes.id", "managedScopes.label", "active");
}
from jackson-antpathfilter.
That works fine! Thanks a lot for that.
Your project is very useful. I wonder why the Jackson library hasn't come up with such a feature yet.
A suggestion is to make the web config slightly more lightweight (so you don't need to explicitely deal with default message converters and super calls) by implementing the WebMvcConfigurer
interface (instead of extending DelegatingWebMvcConfiguration
):
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(0, new AntPathFilterJackson2HttpMessageConverter(objectMapper));
}
}
Apparently the AntPathFilterJackson2HttpMessageConverter
needs to be added at the beginning at the list of message converters, in order to prevent the other message converters from feeling responsible before AntPathFilterJackson2HttpMessageConverter
gets its chance.
from jackson-antpathfilter.
Thanks for the feedback. Once i have time i update the readme.
I didnt know we can give the order of converters. This will simplify my setups alot :)
from jackson-antpathfilter.
Related Issues (12)
- how to: filtering of nested array objects HOT 5
- Support objects other than java beans HOT 4
- java.lang.OutOfMemoryError: GC overhead limit exceeded with version 1.0.2 HOT 1
- Filtering an array
- convertValue not working correctly with antpathfilter HOT 5
- Jackson2Helper and object mapper configuration is not threadsafe HOT 19
- Investigate performance improvement potential HOT 3
- Align exclusion pattern with NPM/Node style -> use ! instead of -
- Use with JAX-RS HOT 2
- addMixInAnnotations instead of addMixIn HOT 2
- antPathFilter seems to be the only supported filter name HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jackson-antpathfilter.