org.zalando.problem.ProblemModule Java Examples

The following examples show how to use org.zalando.problem.ProblemModule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConstraintViolationProblemModuleTest.java    From problem-spring-web with MIT License 6 votes vote down vote up
@Test
void shouldSerializeWithoutAutoDetect() throws JsonProcessingException {
    final JsonMapper mapper = JsonMapper.builder()
            .disable(MapperFeature.AUTO_DETECT_FIELDS)
            .disable(MapperFeature.AUTO_DETECT_GETTERS)
            .disable(MapperFeature.AUTO_DETECT_IS_GETTERS)
            .addModule(new ProblemModule())
            .addModule(new ConstraintViolationProblemModule())
            .build();

    final Violation violation = new Violation("bob", "was missing");
    final ConstraintViolationProblem unit = new ConstraintViolationProblem(BAD_REQUEST, singletonList(violation));

    with(mapper.writeValueAsString(unit))
            .assertThat("status", is(400))
            .assertThat("type", is(ConstraintViolationProblem.TYPE_VALUE))
            .assertThat("title", is("Constraint Violation"))
            .assertThat("violations", hasSize(1))
            .assertThat("violations.*.field", contains("bob"))
            .assertThat("violations.*.message", contains("was missing"));
}
 
Example #2
Source File: SendMoneyExample.java    From quilt with Apache License 2.0 5 votes vote down vote up
/**
 * Construct an {@link ObjectMapper} that can be used to serialize and deserialize ProblemsJSON where JSON numbers
 * emit as non-String values. Because Problems+Json requires HTTP status codes to be serialized as numbers (and not
 * Strings) per RFC-7807, this ObjectMapper should not be used for payloads that involve Problems.
 *
 * @return An {@link ObjectMapper}.
 *
 * @see "https://tools.ietf.org/html/rfc7807"
 */
private static ObjectMapper createObjectMapperForProblemsJson() {
  return new ObjectMapper()
      .registerModule(new Jdk8Module())
      .registerModule(new InterledgerModule(Encoding.BASE64))
      .registerModule(new ProblemModule())
      .registerModule(new ConstraintViolationProblemModule())
      .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
      .configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, false);
}
 
Example #3
Source File: MapperConfiguration.java    From pazuzu-registry with MIT License 5 votes vote down vote up
@Bean
@Primary
public Jackson2ObjectMapperBuilder objectMapperBuilder() {
    Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    return builder
            .failOnUnknownProperties(false)
            .dateFormat(dateFormat)
            .serializationInclusion(Include.NON_NULL)
            .modules(new Jdk8Module(), new ProblemModule());
}
 
Example #4
Source File: JsonConfig.java    From nakadi with MIT License 5 votes vote down vote up
@Bean
@Primary
public ObjectMapper jacksonObjectMapper() {
    final ObjectMapper objectMapper = new ObjectMapper()
            .setPropertyNamingStrategy(SNAKE_CASE);

    objectMapper.registerModule(enumModule());
    objectMapper.registerModule(new Jdk8Module());
    objectMapper.registerModule(new ProblemModule());
    objectMapper.registerModule(new JodaModule());
    objectMapper.configure(WRITE_DATES_AS_TIMESTAMPS , false);
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    return objectMapper;
}
 
Example #5
Source File: ProblemJacksonWebMvcAutoConfiguration.java    From problem-spring-web with MIT License 5 votes vote down vote up
@Override
public void configureMessageConverters(final List<HttpMessageConverter<?>> converters) {
    final ObjectMapper mapper = Jackson2ObjectMapperBuilder.json()
            .modules(
                    new ProblemModule(),
                    new ConstraintViolationProblemModule())
            .build();

    converters.add(new MappingJackson2HttpMessageConverter(mapper));
}
 
Example #6
Source File: ConstraintViolationProblemModuleTest.java    From problem-spring-web with MIT License 5 votes vote down vote up
@Test
void shouldSerializeCustomType() throws JsonProcessingException {
    final ObjectMapper mapper = new ObjectMapper()
            .registerModule(new ProblemModule())
            .registerModule(new ConstraintViolationProblemModule());

    final URI type = URI.create("foo");
    final ConstraintViolationProblem unit = new ConstraintViolationProblem(type, BAD_REQUEST, emptyList());

    with(mapper.writeValueAsString(unit))
            .assertThat("type", is("foo"));
}
 
Example #7
Source File: SecurityAdviceTraitTest.java    From problem-spring-web with MIT License 4 votes vote down vote up
@Bean
public ObjectMapper mapper() {
    return new ObjectMapper().registerModule(new ProblemModule());
}
 
Example #8
Source File: JacksonConfiguration.java    From ehcache3-samples with Apache License 2.0 4 votes vote down vote up
@Bean
ProblemModule problemModule() {
    return new ProblemModule();
}
 
Example #9
Source File: JacksonConfiguration.java    From jhipster-registry with Apache License 2.0 4 votes vote down vote up
@Bean
ProblemModule problemModule() {
    return new ProblemModule();
}
 
Example #10
Source File: ProblemJacksonAutoConfiguration.java    From problem-spring-web with MIT License 4 votes vote down vote up
@Bean
public ProblemModule problemModule() {
    return new ProblemModule();
}
 
Example #11
Source File: WebApplicationTest.java    From problem-spring-web with MIT License 4 votes vote down vote up
@Test
void shouldConfigureProblemModule(
        @Autowired final ProblemModule module) {
    assertThat(module).isNotNull();
}
 
Example #12
Source File: CustomWebMvcApplicationTest.java    From problem-spring-web with MIT License 4 votes vote down vote up
@Test
void shouldNotConfigureProblemModule(
        @Autowired @Nullable final ProblemModule module) {
    assertThat(module).isNull();
}
 
Example #13
Source File: NonWebApplicationTest.java    From problem-spring-web with MIT License 4 votes vote down vote up
@Test
void shouldNotConfigureProblemModule(
        @Autowired @Nullable final ProblemModule module) {
    assertThat(module).isNull();
}
 
Example #14
Source File: NestedThrowableAdviceTraitTest.java    From problem-spring-web with MIT License 4 votes vote down vote up
@Override
public ObjectMapper mapper() {
    return new ObjectMapper().registerModule(new ProblemModule().withStackTraces());
}
 
Example #15
Source File: LocSpringMvcAutoConfiguration.java    From loc-framework with MIT License 4 votes vote down vote up
@Bean
public ProblemModule problemModule() {
  return new ProblemModule();
}
 
Example #16
Source File: AdviceTraitTesting.java    From problem-spring-web with MIT License 4 votes vote down vote up
default ObjectMapper mapper() {
    return new ObjectMapper()
            .registerModule(new ProblemModule())
            .registerModule(new ConstraintViolationProblemModule());
}
 
Example #17
Source File: SecurityAdviceTraitTest.java    From problem-spring-web with MIT License 4 votes vote down vote up
@Override
protected void configureMessageConverters(final List<HttpMessageConverter<?>> converters) {
    converters.clear();
    converters.add(new MappingJackson2HttpMessageConverter(new ObjectMapper()
            .registerModule(new ProblemModule())));
}
 
Example #18
Source File: AdviceTraitTesting.java    From problem-spring-web with MIT License 4 votes vote down vote up
default ObjectMapper mapper() {
    return new ObjectMapper().registerModule(new ProblemModule());
}
 
Example #19
Source File: JacksonConfiguration.java    From 21-points with Apache License 2.0 4 votes vote down vote up
@Bean
ProblemModule problemModule() {
    return new ProblemModule();
}
 
Example #20
Source File: ProblemDemoConfiguration.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public ObjectMapper objectMapper() {
    // In this example, stack traces support is enabled by default. 
    // If you want to disable stack traces just use new ProblemModule() instead of new ProblemModule().withStackTraces()
    return new ObjectMapper().registerModules(new ProblemModule().withStackTraces(), new ConstraintViolationProblemModule());
}
 
Example #21
Source File: JacksonConfiguration.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
ProblemModule problemModule() {
    return new ProblemModule();
}
 
Example #22
Source File: JacksonConfiguration.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
ProblemModule problemModule() {
    return new ProblemModule();
}
 
Example #23
Source File: JacksonConfiguration.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
ProblemModule problemModule() {
    return new ProblemModule();
}
 
Example #24
Source File: JacksonConfiguration.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
ProblemModule problemModule() {
    return new ProblemModule();
}
 
Example #25
Source File: JacksonConfiguration.java    From cubeai with Apache License 2.0 4 votes vote down vote up
@Bean
ProblemModule problemModule() {
    return new ProblemModule();
}
 
Example #26
Source File: JacksonConfiguration.java    From java-microservices-examples with Apache License 2.0 4 votes vote down vote up
@Bean
ProblemModule problemModule() {
    return new ProblemModule();
}
 
Example #27
Source File: JacksonConfiguration.java    From java-microservices-examples with Apache License 2.0 4 votes vote down vote up
@Bean
ProblemModule problemModule() {
    return new ProblemModule();
}
 
Example #28
Source File: JacksonConfiguration.java    From java-microservices-examples with Apache License 2.0 4 votes vote down vote up
@Bean
ProblemModule problemModule() {
    return new ProblemModule();
}
 
Example #29
Source File: JacksonConfiguration.java    From cubeai with Apache License 2.0 4 votes vote down vote up
@Bean
ProblemModule problemModule() {
    return new ProblemModule();
}
 
Example #30
Source File: JacksonConfiguration.java    From cubeai with Apache License 2.0 4 votes vote down vote up
@Bean
ProblemModule problemModule() {
    return new ProblemModule();
}