For jackson 1.9x or below you can ignore unknown properties with object mapper provider
@Provider
@Component
public class JerseyObjectMapperProvider implements ContextResolver<ObjectMapper> {
@Override
public ObjectMapper getContext(Class<?> type) {
ObjectMapper result = new ObjectMapper();
result.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return result;
}
}
For jackson 2.x and above you can ignore unknown properties with object mapper provider
@Provider
@Component
public class JerseyObjectMapperProvider implements ContextResolver<ObjectMapper> {
@Override
public ObjectMapper getContext(Class<?> type) {
ObjectMapper result = new ObjectMapper();
result.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return result;
}
}
Jersey classes are not auto-discovered by Spring. Have to register them manually.
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
register(JerseyObjectMapperProvider.class);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…