Java Code Examples for org.springframework.batch.item.ExecutionContext#putDouble()

The following examples show how to use org.springframework.batch.item.ExecutionContext#putDouble() . 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: ExecutionContextDeserializer.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
public ExecutionContext deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
		throws IOException, JsonProcessingException {
	ObjectCodec oc = jsonParser.getCodec();
	JsonNode node = oc.readTree(jsonParser);

	final ExecutionContext executionContext = new ExecutionContext();
	final boolean dirty = node.get("dirty").asBoolean();

	for (JsonNode valueNode : node.get("values")) {

		final JsonNode nodeValue = valueNode.fields().next().getValue();
		final String nodeKey = valueNode.fields().next().getKey();

		if (nodeValue.isNumber() && !nodeValue.isFloatingPointNumber() && nodeValue.canConvertToInt()) {
			executionContext.putInt(nodeKey, nodeValue.asInt());
		}
		else if (nodeValue.isNumber() && !nodeValue.isFloatingPointNumber() && nodeValue.canConvertToLong()) {
			executionContext.putLong(nodeKey, nodeValue.asLong());
		}
		else if (nodeValue.isFloatingPointNumber()) {
			executionContext.putDouble(nodeKey, nodeValue.asDouble());
		}
		else if (nodeValue.isBoolean()) {
			executionContext.putString(nodeKey, String.valueOf(nodeValue.asBoolean()));
		}
		else if (nodeValue.isTextual()) {
			executionContext.putString(nodeKey, nodeValue.asText());
		}
		else {
			executionContext.put(nodeKey, nodeValue.toString());
		}
	}

	if (!dirty && executionContext.isDirty()) {
		executionContext.clearDirtyFlag();
	}

	return executionContext;
}
 
Example 2
Source File: StepExecutionJacksonMixInTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private StepExecution getStepExecution() {
	JobExecution jobExecution = new JobExecution(1L, null, "hi");
	final StepExecution stepExecution = new StepExecution("step1", jobExecution);
	jobExecution.createStepExecution("step1");
	final ExecutionContext executionContext = stepExecution.getExecutionContext();

	executionContext.putInt("counter", 1234);
	executionContext.putDouble("myDouble", 1.123456d);
	executionContext.putLong("Josh", 4444444444L);
	executionContext.putString("awesomeString", "Yep");
	executionContext.put("hello", "world");
	executionContext.put("counter2", 9999);

	return stepExecution;
}