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 1
1
/*
2
- * Copyright 2018-2021 the original author or authors.
2
+ * Copyright 2018-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
37
37
*
38
38
* @param <T> type of the target object
39
39
* @author Mahmoud Ben Hassine
40
+ * @author Jimmy Praet
40
41
* @since 4.1
41
42
*/
42
43
public class GsonJsonObjectReader <T > implements JsonObjectReader <T > {
@@ -102,4 +103,11 @@ public void close() throws Exception {
102
103
this .jsonReader .close ();
103
104
}
104
105
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
+
105
113
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2018-2021 the original author or authors.
2
+ * Copyright 2018-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
34
34
*
35
35
* @param <T> type of the target object
36
36
* @author Mahmoud Ben Hassine
37
+ * @author Jimmy Praet
37
38
* @since 4.1
38
39
*/
39
40
public class JacksonJsonObjectReader <T > implements JsonObjectReader <T > {
@@ -98,4 +99,13 @@ public void close() throws Exception {
98
99
this .jsonParser .close ();
99
100
}
100
101
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
+
101
111
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2018-2020 the original author or authors.
2
+ * Copyright 2018-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
47
47
*
48
48
* @param <T> the type of json objects to read
49
49
* @author Mahmoud Ben Hassine
50
+ * @author Jimmy Praet
50
51
* @since 4.1
51
52
*/
52
53
public class JsonItemReader <T > extends AbstractItemCountingItemStreamItemReader <T >
@@ -136,4 +137,9 @@ protected void doClose() throws Exception {
136
137
this .jsonObjectReader .close ();
137
138
}
138
139
140
+ @ Override
141
+ protected void jumpToItem (int itemIndex ) throws Exception {
142
+ this .jsonObjectReader .jumpToItem (itemIndex );
143
+ }
144
+
139
145
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2018 the original author or authors.
2
+ * Copyright 2018-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
25
25
*
26
26
* @param <T> type of the target object
27
27
* @author Mahmoud Ben Hassine
28
+ * @author Jimmy Praet
28
29
* @since 4.1
29
30
*/
30
31
public interface JsonObjectReader <T > {
@@ -54,4 +55,18 @@ default void close() throws Exception {
54
55
55
56
}
56
57
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
+
57
72
}
You can’t perform that action at this time.
0 commit comments