org.springframework.integration.support.json.Jackson2JsonObjectMapper Java Examples

The following examples show how to use org.springframework.integration.support.json.Jackson2JsonObjectMapper. 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: User.java    From event-sourcing-microservices-example with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String toString() {
	try {
		return new Jackson2JsonObjectMapper().toJson(this);
	} catch (Exception e) {
		e.printStackTrace();
	}

	return "User{" +
			"id=" + id +
			", userId=" + userId +
			", firstName='" + firstName + '\'' +
			", lastName='" + lastName + '\'' +
			", createdAt=" + createdAt +
			", updatedAt=" + lastModified +
			'}';
}
 
Example #2
Source File: User.java    From event-sourcing-microservices-example with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String toString() {
    try {
        return new Jackson2JsonObjectMapper().toJson(this);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return "User{" +
            "id=" + id +
            ", userId=" + userId +
            ", firstName='" + firstName + '\'' +
            ", lastName='" + lastName + '\'' +
            ", createdAt=" + createdAt +
            ", updatedAt=" + lastModified +
            '}';
}
 
Example #3
Source File: CassandraSinkIntegrationTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Test
public void testIngestQuery() throws Exception {
	List<Book> books = getBookList(5);

	ObjectMapper objectMapper = new ObjectMapper();
	objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
	Jackson2JsonObjectMapper mapper = new Jackson2JsonObjectMapper(objectMapper);

	this.sink.input().send(new GenericMessage<>(mapper.toJson(books)));

	final Select select = QueryBuilder.select().all().from("book");

	assertEqualsEventually(5, new Supplier<Integer>() {

		@Override
		public Integer get() {
			return cassandraTemplate.select(select, Book.class).size();
		}

	});

	this.cassandraTemplate.truncate("book");
}
 
Example #4
Source File: EmployeeRestControllerTest.java    From batchers with Apache License 2.0 6 votes vote down vote up
@Test
public void givenOneEmployee_whenGetEmployees_thenReturnCorrectJson() throws Exception {
    Employee employee = new EmployeeTestBuilder()
            .withIncome(200)
            .withFirstName("firstName")
            .build();

    EmployeeTo employeeTo = new EmployeeTo(employee.getFirstName(), employee.getLastName(), employee.getEmail(), employee.getIncome(), Money.parse("EUR 200"), 1L, 0l);
    String expectedJSON = new Jackson2JsonObjectMapper().toJson(asList(employeeTo));
    when(presentationEmployeeRepository.getEmployees(0, 10)).thenReturn(asList(employeeTo));

    MvcResult mvcResult = mockMvc.perform(get("/employees?page=0&pageSize=10").contentType(MediaType.APPLICATION_JSON))
            .andExpect(status().isOk())
            .andReturn();

    String actualJSON = mvcResult.getResponse().getContentAsString();

    assertThat(actualJSON).isEqualTo(expectedJSON);
}
 
Example #5
Source File: CassandraSinkIntegrationTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Test
public void testIngestQuery() throws Exception {
	List<Book> books = getBookList(5);

	ObjectMapper objectMapper = new ObjectMapper();
	objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
	Jackson2JsonObjectMapper mapper = new Jackson2JsonObjectMapper(objectMapper);

	String booksJsonWithNamedParams = mapper.toJson(books);
	booksJsonWithNamedParams = StringUtils.replace(booksJsonWithNamedParams, "isbn", "myIsbn");
	booksJsonWithNamedParams = StringUtils.replace(booksJsonWithNamedParams, "title", "myTitle");
	booksJsonWithNamedParams = StringUtils.replace(booksJsonWithNamedParams, "author", "myAuthor");
	this.sink.input().send(new GenericMessage<>(booksJsonWithNamedParams));

	final Select select = QueryBuilder.select().all().from("book");

	assertEqualsEventually(5, new Supplier<Integer>() {

		@Override
		public Integer get() {
			return cassandraTemplate.select(select, Book.class).size();
		}

	});

	this.cassandraTemplate.truncate("book");
}
 
Example #6
Source File: JsonMarshaller.java    From citrus-simulator with Apache License 2.0 5 votes vote down vote up
public static String toJson(Object object) {
    final Jackson2JsonObjectMapper mapper = new Jackson2JsonObjectMapper();
    try {
        return mapper.toJson(object);
    } catch (Exception e) {
        throw new SimulatorException(e);
    }
}
 
Example #7
Source File: JsonMarshaller.java    From citrus-simulator with Apache License 2.0 5 votes vote down vote up
public static <T> T fromJson(String json, Class<T> clazz) {
    final Jackson2JsonObjectMapper mapper = new Jackson2JsonObjectMapper();
    try {
        return mapper.fromJson(json, clazz);
    } catch (Exception e) {
        throw new SimulatorException(e);
    }
}
 
Example #8
Source File: SimulatorJmsIT.java    From citrus-simulator with Apache License 2.0 5 votes vote down vote up
private String asJson(ScenarioParameter... scenarioParameters) {
    final Jackson2JsonObjectMapper mapper = new Jackson2JsonObjectMapper();
    try {
        return mapper.toJson(Arrays.asList(scenarioParameters));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #9
Source File: SimulatorWebServiceClientIT.java    From citrus-simulator with Apache License 2.0 5 votes vote down vote up
private String asJson(ScenarioParameter... scenarioParameters) {
    final Jackson2JsonObjectMapper mapper = new Jackson2JsonObjectMapper();
    try {
        return mapper.toJson(Arrays.asList(scenarioParameters));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}