APISonar


org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.json

> org > springframework > http > converter > json > Jackson2ObjectMapperBuilder > json
org APIs springframework APIs http APIs converter APIs json APIs Jackson2ObjectMapperBuilder APIs json APIs

Example 1
public void test_json_format() throws IOException {
		ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();

		Application app = Application.create("test").healthUrl("http://health").serviceUrl("http://service")
				.managementUrl("http://management").build();

		DocumentContext json = JsonPath.parse(objectMapper.writeValueAsString(app));

		assertThat((String) json.read("$.name")).isEqualTo("test");
		assertThat((String) json.read("$.serviceUrl")).isEqualTo("http://service");
		assertThat((String) json.read("$.managementUrl")).isEqualTo("http://management");
		assertThat((String) json.read("$.healthUrl")).isEqualTo("http://health");
	}
Example 2
void jsonFormat() throws Exception {
		AuditEvent event = new AuditEvent("johannes", "UNKNOWN",
				Collections.singletonMap("type", (Object) "BadCredentials"));
		String json = Jackson2ObjectMapperBuilder.json().build().writeValueAsString(event);
		JSONObject jsonObject = new JSONObject(json);
		assertThat(jsonObject.getString("type")).isEqualTo("UNKNOWN");
		assertThat(jsonObject.getJSONObject("data").getString("type")).isEqualTo("BadCredentials");
	}
Example 3
public RegistrationDeserializerTest() {
		SimpleModule module = new SimpleModule();
		module.addDeserializer(Registration.class, new RegistrationDeserializer());
		module.setSerializerModifier(
				new RegistrationBeanSerializerModifier(new SanitizingMapSerializer(new String[] { ".*password$" })));
		objectMapper = Jackson2ObjectMapperBuilder.json().modules(module).build();
	}
Example 4
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.stream()
                .filter(c -> c instanceof MappingJackson2HttpMessageConverter)
                .findFirst().ifPresent(converter -> {
            MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = (MappingJackson2HttpMessageConverter) converter;
            Jackson2ObjectMapperBuilder builder = Jackson2ObjectMapperBuilder.json();
            JsonComponentModule module = new JsonComponentModule();
            module.addSerializer(PageImpl.class, new PageJacksonSerializer());
            ObjectMapper objectMapper = builder.modules(module).build();
            mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper);
        });
    }
Example 5
protected MappingJackson2MessageConverter createJacksonConverter() {
		MappingJackson2MessageConverter messageConverter = super.createJacksonConverter();
		// Use Jackson builder in order to have JSR-310 and Joda-Time modules registered automatically
		messageConverter.setObjectMapper(Jackson2ObjectMapperBuilder.json()
				.applicationContext(this.getApplicationContext()).build());
		return messageConverter;
	}