Add a streaming Json item reader
This commit adds a new Json item reader with two implementations based on Jackson and Gson. Resolves BATCH-2691
This commit is contained in:
committed by
Michael Minella
parent
0dab67c936
commit
5281d6d2aa
@@ -74,6 +74,7 @@ allprojects {
|
||||
hibernateValidatorVersion = '6.0.4.Final'
|
||||
hsqldbVersion = '2.4.0'
|
||||
jackson2Version = '2.9.2'
|
||||
gsonVersion = '2.8.5'
|
||||
javaMailVersion = '1.6.0'
|
||||
javaxBatchApiVersion = '1.0'
|
||||
javaxInjectVersion = '1'
|
||||
@@ -326,6 +327,7 @@ project('spring-batch-infrastructure') {
|
||||
|
||||
optional "javax.jms:javax.jms-api:$jmsVersion"
|
||||
optional "com.fasterxml.jackson.core:jackson-databind:${jackson2Version}"
|
||||
optional "com.google.code.gson:gson:${gsonVersion}"
|
||||
compile("org.hibernate:hibernate-core:$hibernateVersion") { dep ->
|
||||
optional dep
|
||||
exclude group: 'org.jboss.spec.javax.transaction', module: 'jboss-transaction-api_1.1_spec'
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.json;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import org.springframework.batch.item.json.domain.Trade;
|
||||
|
||||
/**
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class GsonJsonItemReaderFunctionalTests extends JsonItemReaderFunctionalTests {
|
||||
|
||||
@Override
|
||||
protected JsonObjectReader<Trade> getJsonObjectReader() {
|
||||
return new GsonJsonObjectReader<>(Trade.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Exception> getJsonParsingException() {
|
||||
return JsonSyntaxException.class;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.json;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
|
||||
import org.springframework.batch.item.json.domain.Trade;
|
||||
|
||||
/**
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class JacksonJsonItemReaderFunctionalTests extends JsonItemReaderFunctionalTests {
|
||||
|
||||
@Override
|
||||
protected JsonObjectReader<Trade> getJsonObjectReader() {
|
||||
return new JacksonJsonObjectReader<>(Trade.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<? extends Exception> getJsonParsingException() {
|
||||
return JsonParseException.class;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.json;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.batch.item.ParseException;
|
||||
import org.springframework.batch.item.json.builder.JsonItemReaderBuilder;
|
||||
import org.springframework.batch.item.json.domain.Trade;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
/**
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public abstract class JsonItemReaderFunctionalTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
protected abstract JsonObjectReader<Trade> getJsonObjectReader();
|
||||
|
||||
protected abstract Class<? extends Exception> getJsonParsingException();
|
||||
|
||||
@Test
|
||||
public void testJsonReading() throws Exception {
|
||||
JsonItemReader<Trade> itemReader = new JsonItemReaderBuilder<Trade>()
|
||||
.jsonObjectReader(getJsonObjectReader())
|
||||
.resource(new ClassPathResource("org/springframework/batch/item/json/trades.json"))
|
||||
.name("tradeJsonItemReader")
|
||||
.build();
|
||||
|
||||
itemReader.open(new ExecutionContext());
|
||||
|
||||
Trade trade = itemReader.read();
|
||||
Assert.assertNotNull(trade);
|
||||
Assert.assertEquals("123", trade.getIsin());
|
||||
Assert.assertEquals("foo", trade.getCustomer());
|
||||
Assert.assertEquals(new BigDecimal("1.2"), trade.getPrice());
|
||||
Assert.assertEquals(1, trade.getQuantity());
|
||||
|
||||
trade = itemReader.read();
|
||||
Assert.assertNotNull(trade);
|
||||
Assert.assertEquals("456", trade.getIsin());
|
||||
Assert.assertEquals("bar", trade.getCustomer());
|
||||
Assert.assertEquals(new BigDecimal("1.4"), trade.getPrice());
|
||||
Assert.assertEquals(2, trade.getQuantity());
|
||||
|
||||
trade = itemReader.read();
|
||||
Assert.assertNull(trade);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyResource() throws Exception {
|
||||
JsonItemReader<Trade> itemReader = new JsonItemReaderBuilder<Trade>()
|
||||
.jsonObjectReader(getJsonObjectReader())
|
||||
.resource(new ByteArrayResource("[]".getBytes()))
|
||||
.name("tradeJsonItemReader")
|
||||
.build();
|
||||
|
||||
itemReader.open(new ExecutionContext());
|
||||
|
||||
Trade trade = itemReader.read();
|
||||
Assert.assertNull(trade);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidResourceFormat() {
|
||||
this.expectedException.expect(ItemStreamException.class);
|
||||
this.expectedException.expectMessage("Failed to initialize the reader");
|
||||
this.expectedException.expectCause(instanceOf(IllegalStateException.class));
|
||||
JsonItemReader<Trade> itemReader = new JsonItemReaderBuilder<Trade>()
|
||||
.jsonObjectReader(getJsonObjectReader())
|
||||
.resource(new ByteArrayResource("{}, {}".getBytes()))
|
||||
.name("tradeJsonItemReader")
|
||||
.build();
|
||||
|
||||
itemReader.open(new ExecutionContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidResourceContent() throws Exception {
|
||||
this.expectedException.expect(ParseException.class);
|
||||
this.expectedException.expectCause(Matchers.instanceOf(getJsonParsingException()));
|
||||
JsonItemReader<Trade> itemReader = new JsonItemReaderBuilder<Trade>()
|
||||
.jsonObjectReader(getJsonObjectReader())
|
||||
.resource(new ByteArrayResource("[{]".getBytes()))
|
||||
.name("tradeJsonItemReader")
|
||||
.build();
|
||||
itemReader.open(new ExecutionContext());
|
||||
|
||||
itemReader.read();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.item.json.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class Trade {
|
||||
|
||||
private String isin = "";
|
||||
|
||||
private long quantity = 0;
|
||||
|
||||
private BigDecimal price = new BigDecimal(0);
|
||||
|
||||
private String customer = "";
|
||||
|
||||
public Trade() {
|
||||
}
|
||||
|
||||
public Trade(String isin, long quantity, BigDecimal price, String customer) {
|
||||
this.isin = isin;
|
||||
this.quantity = quantity;
|
||||
this.price = price;
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
public void setCustomer(String customer) {
|
||||
this.customer = customer;
|
||||
}
|
||||
|
||||
public void setIsin(String isin) {
|
||||
this.isin = isin;
|
||||
}
|
||||
|
||||
public void setPrice(BigDecimal price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public void setQuantity(long quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public String getIsin() {
|
||||
return isin;
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public long getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public String getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Trade: [isin=" + this.isin + ",quantity=" + this.quantity + ",price=" + this.price + ",customer="
|
||||
+ this.customer + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((customer == null) ? 0 : customer.hashCode());
|
||||
result = prime * result + ((isin == null) ? 0 : isin.hashCode());
|
||||
result = prime * result + ((price == null) ? 0 : price.hashCode());
|
||||
result = prime * result + (int) (quantity ^ (quantity >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Trade other = (Trade) obj;
|
||||
if (customer == null) {
|
||||
if (other.customer != null)
|
||||
return false;
|
||||
}
|
||||
else if (!customer.equals(other.customer))
|
||||
return false;
|
||||
if (isin == null) {
|
||||
if (other.isin != null)
|
||||
return false;
|
||||
}
|
||||
else if (!isin.equals(other.isin))
|
||||
return false;
|
||||
if (price == null) {
|
||||
if (other.price != null)
|
||||
return false;
|
||||
}
|
||||
else if (!price.equals(other.price))
|
||||
return false;
|
||||
if (quantity != other.quantity)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"isin": "123",
|
||||
"quantity": 1,
|
||||
"price": 1.2,
|
||||
"customer": "foo"
|
||||
},
|
||||
{
|
||||
"isin": "456",
|
||||
"quantity": 2,
|
||||
"price": 1.4,
|
||||
"customer": "bar"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
|
||||
import org.springframework.batch.item.ParseException;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Implementation of {@link JsonObjectReader} based on
|
||||
* <a href="https://github.com/google/gson">Google Gson</a>.
|
||||
*
|
||||
* @param <T> type of the target object
|
||||
*
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 4.1
|
||||
*/
|
||||
public class GsonJsonObjectReader<T> implements JsonObjectReader<T> {
|
||||
|
||||
private Class<? extends T> itemType;
|
||||
|
||||
private JsonReader jsonReader;
|
||||
|
||||
private Gson mapper = new Gson();
|
||||
|
||||
private InputStream inputStream;
|
||||
|
||||
/**
|
||||
* Create a new {@link GsonJsonObjectReader} instance.
|
||||
* @param itemType the target item type
|
||||
*/
|
||||
public GsonJsonObjectReader(Class<? extends T> itemType) {
|
||||
this.itemType = itemType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the object mapper to use to map Json objects to domain objects.
|
||||
* @param mapper the object mapper to use
|
||||
*/
|
||||
public void setMapper(Gson mapper) {
|
||||
Assert.notNull(mapper, "The mapper must not be null");
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(Resource resource) throws Exception {
|
||||
Assert.notNull(resource, "The resource must not be null");
|
||||
this.inputStream = resource.getInputStream();
|
||||
this.jsonReader = this.mapper.newJsonReader(new InputStreamReader(this.inputStream));
|
||||
Assert.state(this.jsonReader.peek() == JsonToken.BEGIN_ARRAY,
|
||||
"The Json input stream must start with an array of Json objects");
|
||||
this.jsonReader.beginArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T read() throws Exception {
|
||||
try {
|
||||
if (this.jsonReader.hasNext()) {
|
||||
return this.mapper.fromJson(this.jsonReader, this.itemType);
|
||||
}
|
||||
} catch (IOException |JsonIOException | JsonSyntaxException e) {
|
||||
throw new ParseException("Unable to read next JSON object", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
this.inputStream.close();
|
||||
this.jsonReader.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.springframework.batch.item.ParseException;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Implementation of {@link JsonObjectReader} based on
|
||||
* <a href="https://github.com/FasterXML/jackson">Jackson</a>.
|
||||
*
|
||||
* @param <T> type of the target object
|
||||
*
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 4.1
|
||||
*/
|
||||
public class JacksonJsonObjectReader<T> implements JsonObjectReader<T> {
|
||||
|
||||
private Class<? extends T> itemType;
|
||||
|
||||
private JsonParser jsonParser;
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
private InputStream inputStream;
|
||||
|
||||
/**
|
||||
* Create a new {@link JacksonJsonObjectReader} instance.
|
||||
* @param itemType the target item type
|
||||
*/
|
||||
public JacksonJsonObjectReader(Class<? extends T> itemType) {
|
||||
this.itemType = itemType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the object mapper to use to map Json objects to domain objects.
|
||||
* @param mapper the object mapper to use
|
||||
*/
|
||||
public void setMapper(ObjectMapper mapper) {
|
||||
Assert.notNull(mapper, "The mapper must not be null");
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(Resource resource) throws Exception {
|
||||
Assert.notNull(resource, "The resource must not be null");
|
||||
this.inputStream = resource.getInputStream();
|
||||
this.jsonParser = this.mapper.getFactory().createParser(this.inputStream);
|
||||
Assert.state(this.jsonParser.nextToken() == JsonToken.START_ARRAY,
|
||||
"The Json input stream must start with an array of Json objects");
|
||||
}
|
||||
|
||||
@Override
|
||||
public T read() throws Exception {
|
||||
try {
|
||||
if (this.jsonParser.nextToken() == JsonToken.START_OBJECT) {
|
||||
return this.mapper.readValue(this.jsonParser, this.itemType);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ParseException("Unable to read next JSON object", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
this.inputStream.close();
|
||||
this.jsonParser.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.json;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.batch.item.ItemStreamReader;
|
||||
import org.springframework.batch.item.file.ResourceAwareItemReaderItemStream;
|
||||
import org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link ItemStreamReader} implementation that reads Json objects from a
|
||||
* {@link Resource} having the following format:
|
||||
* <p>
|
||||
* <code>
|
||||
* [
|
||||
* {
|
||||
* // JSON object
|
||||
* },
|
||||
* {
|
||||
* // JSON object
|
||||
* }
|
||||
* ]
|
||||
* </code>
|
||||
* <p>
|
||||
*
|
||||
* The implementation is <b>not</b> thread-safe.
|
||||
*
|
||||
* @param <T> the type of json objects to read
|
||||
*
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 4.1
|
||||
*/
|
||||
public class JsonItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements
|
||||
ResourceAwareItemReaderItemStream<T> {
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog(JsonItemReader.class);
|
||||
|
||||
private Resource resource;
|
||||
|
||||
private JsonObjectReader<T> jsonObjectReader;
|
||||
|
||||
private boolean strict = true;
|
||||
|
||||
/**
|
||||
* Create a new {@link JsonItemReader} instance.
|
||||
* @param resource the input json resource
|
||||
* @param jsonObjectReader the json object reader to use
|
||||
*/
|
||||
public JsonItemReader(Resource resource, JsonObjectReader<T> jsonObjectReader) {
|
||||
Assert.notNull(resource, "The resource must not be null.");
|
||||
Assert.notNull(jsonObjectReader, "The json object reader must not be null.");
|
||||
this.resource = resource;
|
||||
this.jsonObjectReader = jsonObjectReader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link JsonObjectReader} to use to read and map Json fragments to domain objects.
|
||||
* @param jsonObjectReader the json object reader to use
|
||||
*/
|
||||
public void setJsonObjectReader(JsonObjectReader<T> jsonObjectReader) {
|
||||
this.jsonObjectReader = jsonObjectReader;
|
||||
}
|
||||
|
||||
/**
|
||||
* In strict mode the reader will throw an exception on
|
||||
* {@link #open(org.springframework.batch.item.ExecutionContext)} if the
|
||||
* input resource does not exist.
|
||||
* @param strict true by default
|
||||
*/
|
||||
public void setStrict(boolean strict) {
|
||||
this.strict = strict;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResource(Resource resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T doRead() throws Exception {
|
||||
return jsonObjectReader.read();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doOpen() throws Exception {
|
||||
if (!this.resource.exists()) {
|
||||
if (this.strict) {
|
||||
throw new IllegalStateException("Input resource must exist (reader is in 'strict' mode)");
|
||||
}
|
||||
LOGGER.warn("Input resource does not exist " + this.resource.getDescription());
|
||||
return;
|
||||
}
|
||||
if (!this.resource.isReadable()) {
|
||||
if (this.strict) {
|
||||
throw new IllegalStateException("Input resource must be readable (reader is in 'strict' mode)");
|
||||
}
|
||||
LOGGER.warn("Input resource is not readable " + this.resource.getDescription());
|
||||
return;
|
||||
}
|
||||
this.jsonObjectReader.open(this.resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doClose() throws Exception {
|
||||
this.jsonObjectReader.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.json;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* Strategy interface for Json readers. Implementations are expected to use
|
||||
* a streaming API in order to read Json objects one at a time.
|
||||
*
|
||||
* @param <T> type of the target object
|
||||
*
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 4.1
|
||||
*/
|
||||
public interface JsonObjectReader<T> {
|
||||
|
||||
/**
|
||||
* Open the Json resource for reading.
|
||||
* @param resource the input resource
|
||||
* @throws Exception if unable to open the resource
|
||||
*/
|
||||
default void open(Resource resource) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the next object in the Json resource if any.
|
||||
* @return the next object or null if the resource is exhausted
|
||||
* @throws Exception if unable to read the next object
|
||||
*/
|
||||
T read() throws Exception;
|
||||
|
||||
/**
|
||||
* Close the input resource.
|
||||
* @throws Exception if unable to close the input resource
|
||||
*/
|
||||
default void close() throws Exception {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.json.builder;
|
||||
|
||||
import org.springframework.batch.item.json.JsonItemReader;
|
||||
import org.springframework.batch.item.json.JsonObjectReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A builder for {@link JsonItemReader}.
|
||||
*
|
||||
* @param <T> type of the target item
|
||||
*
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 4.1
|
||||
*/
|
||||
public class JsonItemReaderBuilder<T> {
|
||||
|
||||
private JsonObjectReader<T> jsonObjectReader;
|
||||
|
||||
private Resource resource;
|
||||
|
||||
private String name;
|
||||
|
||||
private boolean strict = true;
|
||||
|
||||
private boolean saveState = true;
|
||||
|
||||
private int maxItemCount = Integer.MAX_VALUE;
|
||||
|
||||
private int currentItemCount;
|
||||
|
||||
/**
|
||||
* Set the {@link JsonObjectReader} to use to read and map Json objects to domain objects.
|
||||
* @param jsonObjectReader to use
|
||||
* @return The current instance of the builder.
|
||||
* @see JsonItemReader#setJsonObjectReader(JsonObjectReader)
|
||||
*/
|
||||
public JsonItemReaderBuilder<T> jsonObjectReader(JsonObjectReader<T> jsonObjectReader) {
|
||||
this.jsonObjectReader = jsonObjectReader;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link Resource} to be used as input.
|
||||
* @param resource the input to the reader.
|
||||
* @return The current instance of the builder.
|
||||
* @see JsonItemReader#setResource(Resource)
|
||||
*/
|
||||
public JsonItemReaderBuilder<T> resource(Resource resource) {
|
||||
this.resource = resource;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name used to calculate the key within the
|
||||
* {@link org.springframework.batch.item.ExecutionContext}. Required if
|
||||
* {@link #saveState(boolean)} is set to true.
|
||||
* @param name name of the reader instance
|
||||
* @return The current instance of the builder.
|
||||
* @see org.springframework.batch.item.ItemStreamSupport#setName(String)
|
||||
*/
|
||||
public JsonItemReaderBuilder<T> name(String name) {
|
||||
this.name = name;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setting this value to true indicates that it is an error if the input
|
||||
* does not exist and an exception will be thrown. Defaults to true.
|
||||
* @param strict indicates the input resource must exist
|
||||
* @return The current instance of the builder.
|
||||
* @see JsonItemReader#setStrict(boolean)
|
||||
*/
|
||||
public JsonItemReaderBuilder<T> strict(boolean strict) {
|
||||
this.strict = strict;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure if the state of the {@link org.springframework.batch.item.ItemStreamSupport}
|
||||
* should be persisted within the {@link org.springframework.batch.item.ExecutionContext}
|
||||
* for restart purposes.
|
||||
* @param saveState defaults to true
|
||||
* @return The current instance of the builder.
|
||||
*/
|
||||
public JsonItemReaderBuilder<T> saveState(boolean saveState) {
|
||||
this.saveState = saveState;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the max number of items to be read.
|
||||
* @param maxItemCount the max items to be read
|
||||
* @return The current instance of the builder.
|
||||
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setMaxItemCount(int)
|
||||
*/
|
||||
public JsonItemReaderBuilder<T> maxItemCount(int maxItemCount) {
|
||||
this.maxItemCount = maxItemCount;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Index for the current item. Used on restarts to indicate where to start from.
|
||||
* @param currentItemCount current index
|
||||
* @return The current instance of the builder.
|
||||
* @see org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader#setCurrentItemCount(int)
|
||||
*/
|
||||
public JsonItemReaderBuilder<T> currentItemCount(int currentItemCount) {
|
||||
this.currentItemCount = currentItemCount;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the configuration and build a new {@link JsonItemReader}.
|
||||
* @return a new instance of the {@link JsonItemReader}
|
||||
*/
|
||||
public JsonItemReader<T> build() {
|
||||
Assert.notNull(this.jsonObjectReader, "A json object reader is required.");
|
||||
Assert.notNull(this.resource, "A resource is required.");
|
||||
if (this.saveState) {
|
||||
Assert.state(StringUtils.hasText(this.name), "A name is required when saveState is set to true.");
|
||||
}
|
||||
|
||||
JsonItemReader<T> reader = new JsonItemReader<>(this.resource, this.jsonObjectReader);
|
||||
reader.setName(this.name);
|
||||
reader.setStrict(this.strict);
|
||||
reader.setSaveState(this.saveState);
|
||||
reader.setMaxItemCount(this.maxItemCount);
|
||||
reader.setCurrentItemCount(this.currentItemCount);
|
||||
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.json;
|
||||
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
|
||||
/**
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class GsonJsonItemReaderCommonTests extends JsonItemReaderCommonTests {
|
||||
|
||||
@Override
|
||||
protected JsonObjectReader<Foo> getJsonObjectReader() {
|
||||
return new GsonJsonObjectReader<>(Foo.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.json;
|
||||
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
|
||||
/**
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class JacksonJsonItemReaderCommonTests extends JsonItemReaderCommonTests {
|
||||
|
||||
@Override
|
||||
protected JsonObjectReader<Foo> getJsonObjectReader() {
|
||||
return new JacksonJsonObjectReader<>(Foo.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.json;
|
||||
|
||||
import org.springframework.batch.item.AbstractItemStreamItemReaderTests;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
|
||||
/**
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public abstract class JsonItemReaderCommonTests extends AbstractItemStreamItemReaderTests {
|
||||
|
||||
private static final String FOOS = "[" +
|
||||
" {\"value\":1}," +
|
||||
" {\"value\":2}," +
|
||||
" {\"value\":3}," +
|
||||
" {\"value\":4}," +
|
||||
" {\"value\":5}" +
|
||||
"]";
|
||||
|
||||
protected abstract JsonObjectReader<Foo> getJsonObjectReader();
|
||||
|
||||
@Override
|
||||
protected ItemReader<Foo> getItemReader() {
|
||||
ByteArrayResource resource = new ByteArrayResource(FOOS.getBytes());
|
||||
JsonObjectReader<Foo> jsonObjectReader = getJsonObjectReader();
|
||||
JsonItemReader<Foo> itemReader = new JsonItemReader<>(resource, jsonObjectReader);
|
||||
itemReader.setName("fooJsonItemReader");
|
||||
return itemReader;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void pointToEmptyInput(ItemReader<Foo> tested) {
|
||||
JsonItemReader<Foo> reader = (JsonItemReader<Foo>) tested;
|
||||
reader.setResource(new ByteArrayResource("[]".getBytes()));
|
||||
|
||||
reader.open(new ExecutionContext());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.json;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.core.io.AbstractResource;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class JsonItemReaderTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
private JsonObjectReader<String> jsonObjectReader;
|
||||
|
||||
private JsonItemReader<String> itemReader;
|
||||
|
||||
@Test
|
||||
public void testValidation() {
|
||||
try {
|
||||
new JsonItemReader<>(null, this.jsonObjectReader);
|
||||
fail("A resource is required.");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
assertEquals("The resource must not be null.", iae.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
new JsonItemReader<>(new ByteArrayResource("[{}]".getBytes()), null);
|
||||
fail("A json object reader is required.");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
assertEquals("The json object reader must not be null.", iae.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonExistentResource() {
|
||||
// given
|
||||
this.expectedException.expect(ItemStreamException.class);
|
||||
this.expectedException.expectMessage("Failed to initialize the reader");
|
||||
this.expectedException.expectCause(Matchers.instanceOf(IllegalStateException.class));
|
||||
this.itemReader = new JsonItemReader<>(new NonExistentResource(), this.jsonObjectReader);
|
||||
|
||||
// when
|
||||
this.itemReader.open(new ExecutionContext());
|
||||
|
||||
// then
|
||||
// expected exception
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonReadableResource() {
|
||||
// given
|
||||
this.expectedException.expect(ItemStreamException.class);
|
||||
this.expectedException.expectMessage("Failed to initialize the reader");
|
||||
this.expectedException.expectCause(Matchers.instanceOf(IllegalStateException.class));
|
||||
this.itemReader = new JsonItemReader<>(new NonReadableResource(), this.jsonObjectReader);
|
||||
|
||||
// when
|
||||
this.itemReader.open(new ExecutionContext());
|
||||
|
||||
// then
|
||||
// expected exception
|
||||
}
|
||||
|
||||
private static class NonExistentResource extends AbstractResource {
|
||||
|
||||
NonExistentResource() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "NonExistentResource";
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class NonReadableResource extends AbstractResource {
|
||||
|
||||
NonReadableResource() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "NonReadableResource";
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.json.builder;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.springframework.batch.item.json.JsonItemReader;
|
||||
import org.springframework.batch.item.json.JsonObjectReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.springframework.test.util.ReflectionTestUtils.getField;
|
||||
|
||||
/**
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class JsonItemReaderBuilderTest {
|
||||
|
||||
@Mock
|
||||
private Resource resource;
|
||||
@Mock
|
||||
private JsonObjectReader<String> jsonObjectReader;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidation() {
|
||||
try {
|
||||
new JsonItemReaderBuilder<String>()
|
||||
.build();
|
||||
fail("A json object reader is required.");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("A json object reader is required.",
|
||||
iae.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
new JsonItemReaderBuilder<String>()
|
||||
.jsonObjectReader(this.jsonObjectReader)
|
||||
.build();
|
||||
fail("A resource is required.");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("A resource is required.",
|
||||
iae.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
new JsonItemReaderBuilder<String>()
|
||||
.jsonObjectReader(this.jsonObjectReader)
|
||||
.resource(this.resource)
|
||||
.build();
|
||||
fail("A name is required when saveState is set to true.");
|
||||
}
|
||||
catch (IllegalStateException iae) {
|
||||
assertEquals("A name is required when saveState is set to true.",
|
||||
iae.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfiguration() {
|
||||
JsonItemReader<String> itemReader = new JsonItemReaderBuilder<String>()
|
||||
.jsonObjectReader(this.jsonObjectReader)
|
||||
.resource(this.resource)
|
||||
.saveState(true)
|
||||
.strict(true)
|
||||
.name("jsonItemReader")
|
||||
.maxItemCount(100)
|
||||
.currentItemCount(50)
|
||||
.build();
|
||||
|
||||
Assert.assertEquals(this.jsonObjectReader, getField(itemReader, "jsonObjectReader"));
|
||||
Assert.assertEquals(this.resource, getField(itemReader, "resource"));
|
||||
Assert.assertEquals(100, getField(itemReader, "maxItemCount"));
|
||||
Assert.assertEquals(50, getField(itemReader, "currentItemCount"));
|
||||
Assert.assertTrue((Boolean) getField(itemReader, "saveState"));
|
||||
Assert.assertTrue((Boolean) getField(itemReader, "strict"));
|
||||
Object executionContext = getField(itemReader, "executionContextUserSupport");
|
||||
Assert.assertEquals("jsonItemReader", getField(executionContext, "name"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user