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

The following examples show how to use org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper#writeValueAsString() . 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: Pipeline.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public String toJson() {
	ObjectMapper mapper = new ObjectMapper();

	List<Map<String, String>> stageJsons = new ArrayList<>();
	for (PipelineStage s : getStages()) {
		Map<String, String> stageMap = new HashMap<>();
		stageMap.put("stageClassName", s.getClass().getTypeName());
		stageMap.put("stageJson", s.toJson());
		stageJsons.add(stageMap);
	}

	try {
		return mapper.writeValueAsString(stageJsons);
	} catch (JsonProcessingException e) {
		throw new RuntimeException("Failed to serialize pipeline", e);
	}
}
 
Example 4
Source File: Pipeline.java    From Alink with Apache License 2.0 6 votes vote down vote up
@Override
public String toJson() {
	ObjectMapper mapper = new ObjectMapper();

	List<Map<String, String>> stageJsons = new ArrayList<>();
	for (PipelineStage s : getStages()) {
		Map<String, String> stageMap = new HashMap<>();
		stageMap.put("stageClassName", s.getClass().getTypeName());
		stageMap.put("stageJson", s.toJson());
		stageJsons.add(stageMap);
	}

	try {
		return mapper.writeValueAsString(stageJsons);
	} catch (JsonProcessingException e) {
		throw new RuntimeException("Failed to toString pipeline", e);
	}
}
 
Example 5
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 6
Source File: Pipeline.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public String toJson() {
	ObjectMapper mapper = new ObjectMapper();

	List<Map<String, String>> stageJsons = new ArrayList<>();
	for (PipelineStage s : getStages()) {
		Map<String, String> stageMap = new HashMap<>();
		stageMap.put("stageClassName", s.getClass().getTypeName());
		stageMap.put("stageJson", s.toJson());
		stageJsons.add(stageMap);
	}

	try {
		return mapper.writeValueAsString(stageJsons);
	} catch (JsonProcessingException e) {
		throw new RuntimeException("Failed to serialize pipeline", e);
	}
}
 
Example 7
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 8
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 9
Source File: ControlMessage.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
public ControlMessage(ControlEvent event) {
    this.type = event.getClass().getName();
    ObjectMapper mapper = new ObjectMapper();
    try {
        this.payload = mapper.writeValueAsString(event);
    } catch (JsonProcessingException e) {
        throw new IllegalArgumentException(e);
    }
}
 
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);
}