Java Code Examples for org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper#readValue()

The following examples show how to use org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper#readValue() . 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: RestResponseMarshallingTestBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that we can marshal and unmarshal the response.
 */
@Test
public void testJsonMarshalling() throws Exception {
	final R expected = getTestResponseInstance();

	ObjectMapper objectMapper = RestMapperUtils.getStrictObjectMapper();
	final String marshalled = objectMapper.writeValueAsString(expected);

	final Collection<Class<?>> typeParameters = getTypeParameters();
	final JavaType type;

	if (typeParameters.isEmpty()) {
		type = objectMapper.getTypeFactory().constructType(getTestResponseClass());
	} else {
		type = objectMapper.getTypeFactory().constructParametricType(
			getTestResponseClass(),
			typeParameters.toArray(new Class<?>[typeParameters.size()]));
	}

	final R unmarshalled = objectMapper.readValue(marshalled, type);
	assertOriginalEqualsToUnmarshalled(expected, unmarshalled);
}
 
Example 2
Source File: RestResponseMarshallingTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that we can marshal and unmarshal the response.
 */
@Test
public void testJsonMarshalling() throws Exception {
	final R expected = getTestResponseInstance();

	ObjectMapper objectMapper = RestMapperUtils.getStrictObjectMapper();
	final String marshalled = objectMapper.writeValueAsString(expected);

	final Collection<Class<?>> typeParameters = getTypeParameters();
	final JavaType type;

	if (typeParameters.isEmpty()) {
		type = objectMapper.getTypeFactory().constructType(getTestResponseClass());
	} else {
		type = objectMapper.getTypeFactory().constructParametricType(
			getTestResponseClass(),
			typeParameters.toArray(new Class<?>[typeParameters.size()]));
	}

	final R unmarshalled = objectMapper.readValue(marshalled, type);
	assertOriginalEqualsToUnmarshalled(expected, unmarshalled);
}
 
Example 3
Source File: RestResponseMarshallingTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that we can marshal and unmarshal the response.
 */
@Test
public void testJsonMarshalling() throws Exception {
	final R expected = getTestResponseInstance();

	ObjectMapper objectMapper = RestMapperUtils.getStrictObjectMapper();
	final String marshalled = objectMapper.writeValueAsString(expected);

	final Collection<Class<?>> typeParameters = getTypeParameters();
	final JavaType type;

	if (typeParameters.isEmpty()) {
		type = objectMapper.getTypeFactory().constructType(getTestResponseClass());
	} else {
		type = objectMapper.getTypeFactory().constructParametricType(
			getTestResponseClass(),
			typeParameters.toArray(new Class<?>[typeParameters.size()]));
	}

	final R unmarshalled = objectMapper.readValue(marshalled, type);
	assertOriginalEqualsToUnmarshalled(expected, unmarshalled);
}
 
Example 4
Source File: HistoryServerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testHistoryServerIntegration() throws Exception {
	final int numJobs = 2;
	for (int x = 0; x < numJobs; x++) {
		runJob();
	}
	createLegacyArchive(jmDirectory.toPath());

	CountDownLatch numFinishedPolls = new CountDownLatch(1);

	Configuration historyServerConfig = new Configuration();
	historyServerConfig.setString(HistoryServerOptions.HISTORY_SERVER_ARCHIVE_DIRS, jmDirectory.toURI().toString());
	historyServerConfig.setString(HistoryServerOptions.HISTORY_SERVER_WEB_DIR, hsDirectory.getAbsolutePath());

	historyServerConfig.setInteger(HistoryServerOptions.HISTORY_SERVER_WEB_PORT, 0);

	// the job is archived asynchronously after env.execute() returns
	File[] archives = jmDirectory.listFiles();
	while (archives == null || archives.length != numJobs + 1) {
		Thread.sleep(50);
		archives = jmDirectory.listFiles();
	}

	HistoryServer hs = new HistoryServer(historyServerConfig, numFinishedPolls);
	try {
		hs.start();
		String baseUrl = "http://localhost:" + hs.getWebPort();
		numFinishedPolls.await(10L, TimeUnit.SECONDS);

		ObjectMapper mapper = new ObjectMapper();
		String response = getFromHTTP(baseUrl + JobsOverviewHeaders.URL);
		MultipleJobsDetails overview = mapper.readValue(response, MultipleJobsDetails.class);

		Assert.assertEquals(numJobs + 1, overview.getJobs().size());
	} finally {
		hs.stop();
	}
}
 
Example 5
Source File: RestRequestMarshallingTestBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that we can marshal and unmarshal the response.
 */
@Test
public void testJsonMarshalling() throws Exception {
	final R expected = getTestRequestInstance();

	ObjectMapper objectMapper = RestMapperUtils.getStrictObjectMapper();
	final String marshalled = objectMapper.writeValueAsString(expected);

	final R unmarshalled = objectMapper.readValue(marshalled, getTestRequestClass());
	assertOriginalEqualsToUnmarshalled(expected, unmarshalled);
}
 
Example 6
Source File: HistoryServerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testHistoryServerIntegration() throws Exception {
	final int numJobs = 2;
	for (int x = 0; x < numJobs; x++) {
		runJob();
	}
	createLegacyArchive(jmDirectory.toPath());

	CountDownLatch numFinishedPolls = new CountDownLatch(1);

	Configuration historyServerConfig = new Configuration();
	historyServerConfig.setString(HistoryServerOptions.HISTORY_SERVER_ARCHIVE_DIRS, jmDirectory.toURI().toString());
	historyServerConfig.setString(HistoryServerOptions.HISTORY_SERVER_WEB_DIR, hsDirectory.getAbsolutePath());

	historyServerConfig.setInteger(HistoryServerOptions.HISTORY_SERVER_WEB_PORT, 0);

	// the job is archived asynchronously after env.execute() returns
	File[] archives = jmDirectory.listFiles();
	while (archives == null || archives.length != numJobs + 1) {
		Thread.sleep(50);
		archives = jmDirectory.listFiles();
	}

	HistoryServer hs = new HistoryServer(historyServerConfig, numFinishedPolls);
	try {
		hs.start();
		String baseUrl = "http://localhost:" + hs.getWebPort();
		numFinishedPolls.await(10L, TimeUnit.SECONDS);

		ObjectMapper mapper = new ObjectMapper();
		String response = getFromHTTP(baseUrl + JobsOverviewHeaders.URL);
		MultipleJobsDetails overview = mapper.readValue(response, MultipleJobsDetails.class);

		Assert.assertEquals(numJobs + 1, overview.getJobs().size());
	} finally {
		hs.stop();
	}
}
 
Example 7
Source File: RestRequestMarshallingTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that we can marshal and unmarshal the response.
 */
@Test
public void testJsonMarshalling() throws Exception {
	final R expected = getTestRequestInstance();

	ObjectMapper objectMapper = RestMapperUtils.getStrictObjectMapper();
	final String marshalled = objectMapper.writeValueAsString(expected);

	final R unmarshalled = objectMapper.readValue(marshalled, getTestRequestClass());
	assertOriginalEqualsToUnmarshalled(expected, unmarshalled);
}
 
Example 8
Source File: Pipeline.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void loadJson(String json) {
	ObjectMapper mapper = new ObjectMapper();
	List<Map<String, String>> stageJsons;
	try {
		stageJsons = mapper.readValue(json, List.class);
	} catch (IOException e) {
		throw new RuntimeException("Failed to deserialize pipeline json:" + json, e);
	}
	for (Map<String, String> stageMap : stageJsons) {
		appendStage(restoreInnerStage(stageMap));
	}
}
 
Example 9
Source File: Pipeline.java    From Alink with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void loadJson(String json) {
	ObjectMapper mapper = new ObjectMapper();
	List<Map<String, String>> stageJsons;
	try {
		stageJsons = mapper.readValue(json, List.class);
	} catch (IOException e) {
		throw new RuntimeException("Failed to parseDense pipeline json:" + json, e);
	}
	for (Map<String, String> stageMap : stageJsons) {
		appendStage(restoreInnerStage(stageMap));
	}
}
 
Example 10
Source File: RestRequestMarshallingTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that we can marshal and unmarshal the response.
 */
@Test
public void testJsonMarshalling() throws Exception {
	final R expected = getTestRequestInstance();

	ObjectMapper objectMapper = RestMapperUtils.getStrictObjectMapper();
	final String marshalled = objectMapper.writeValueAsString(expected);

	final R unmarshalled = objectMapper.readValue(marshalled, getTestRequestClass());
	assertOriginalEqualsToUnmarshalled(expected, unmarshalled);
}
 
Example 11
Source File: Pipeline.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void loadJson(String json) {
	ObjectMapper mapper = new ObjectMapper();
	List<Map<String, String>> stageJsons;
	try {
		stageJsons = mapper.readValue(json, List.class);
	} catch (IOException e) {
		throw new RuntimeException("Failed to deserialize pipeline json:" + json, e);
	}
	for (Map<String, String> stageMap : stageJsons) {
		appendStage(restoreInnerStage(stageMap));
	}
}