File tree Expand file tree Collapse file tree 4 files changed +43
-4
lines changed
spring-batch-infrastructure/src/main/java/org/springframework/batch/item/json Expand file tree Collapse file tree 4 files changed +43
-4
lines changed Original file line number Diff line number Diff line change 11/*
2- * Copyright 2018-2021 the original author or authors.
2+ * Copyright 2018-2024 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3737 *
3838 * @param <T> type of the target object
3939 * @author Mahmoud Ben Hassine
40+ * @author Jimmy Praet
4041 * @since 4.1
4142 */
4243public class GsonJsonObjectReader <T > implements JsonObjectReader <T > {
@@ -102,4 +103,11 @@ public void close() throws Exception {
102103 this .jsonReader .close ();
103104 }
104105
106+ @ Override
107+ public void jumpToItem (int itemIndex ) throws Exception {
108+ for (int i = 0 ; i < itemIndex ; i ++) {
109+ this .jsonReader .skipValue ();
110+ }
111+ }
112+
105113}
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2018-2021 the original author or authors.
2+ * Copyright 2018-2024 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3434 *
3535 * @param <T> type of the target object
3636 * @author Mahmoud Ben Hassine
37+ * @author Jimmy Praet
3738 * @since 4.1
3839 */
3940public class JacksonJsonObjectReader <T > implements JsonObjectReader <T > {
@@ -98,4 +99,13 @@ public void close() throws Exception {
9899 this .jsonParser .close ();
99100 }
100101
102+ @ Override
103+ public void jumpToItem (int itemIndex ) throws Exception {
104+ for (int i = 0 ; i < itemIndex ; i ++) {
105+ if (this .jsonParser .nextToken () == JsonToken .START_OBJECT ) {
106+ this .jsonParser .skipChildren ();
107+ }
108+ }
109+ }
110+
101111}
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2018-2020 the original author or authors.
2+ * Copyright 2018-2024 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
4747 *
4848 * @param <T> the type of json objects to read
4949 * @author Mahmoud Ben Hassine
50+ * @author Jimmy Praet
5051 * @since 4.1
5152 */
5253public class JsonItemReader <T > extends AbstractItemCountingItemStreamItemReader <T >
@@ -136,4 +137,9 @@ protected void doClose() throws Exception {
136137 this .jsonObjectReader .close ();
137138 }
138139
140+ @ Override
141+ protected void jumpToItem (int itemIndex ) throws Exception {
142+ this .jsonObjectReader .jumpToItem (itemIndex );
143+ }
144+
139145}
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2018 the original author or authors.
2+ * Copyright 2018-2024 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2525 *
2626 * @param <T> type of the target object
2727 * @author Mahmoud Ben Hassine
28+ * @author Jimmy Praet
2829 * @since 4.1
2930 */
3031public interface JsonObjectReader <T > {
@@ -54,4 +55,18 @@ default void close() throws Exception {
5455
5556 }
5657
58+ /**
59+ * Move to the given item index. Subclasses should override this method if there is a
60+ * more efficient way of moving to given index than re-reading the input using
61+ * {@link #read()}.
62+ * @param itemIndex index of item (0 based) to jump to.
63+ * @throws Exception Allows subclasses to throw checked exceptions for interpretation
64+ * by the framework
65+ */
66+ default void jumpToItem (int itemIndex ) throws Exception {
67+ for (int i = 0 ; i < itemIndex ; i ++) {
68+ read ();
69+ }
70+ }
71+
5772}
You can’t perform that action at this time.
0 commit comments