@@ -2,55 +2,37 @@ package pure
2
2
3
3
import (
4
4
"context"
5
- json "encoding/json"
6
- "errors"
5
+ "encoding/json"
7
6
"io"
8
7
9
8
"github.com/benthosdev/benthos/v4/public/service"
10
9
)
11
10
12
- const (
13
- sjsonFieldContinueOnError = "continue_on_error"
14
- )
15
-
16
11
func jsonDocumentScannerSpec () * service.ConfigSpec {
17
12
return service .NewConfigSpec ().
18
13
Stable ().
14
+ Version ("4.27.0" ).
19
15
Summary ("Consumes a stream of one or more JSON documents." ).
20
- Fields (
21
- service .NewBoolField (sjsonFieldContinueOnError ).
22
- Description ("If a JSON decoding fails due to any error emit an empty message marked with the error and then continue consuming subsequent documents when possible." ).
23
- Default (false ),
24
- )
16
+ // Just a placeholder empty object as we don't have any fields yet
17
+ Field (service .NewObjectField ("" ).Default (map [string ]any {}))
25
18
}
26
19
27
20
func init () {
28
21
err := service .RegisterBatchScannerCreator ("json_documents" , jsonDocumentScannerSpec (),
29
22
func (conf * service.ParsedConfig , mgr * service.Resources ) (service.BatchScannerCreator , error ) {
30
- return jsonDocumentScannerFromParsed ( conf )
23
+ return & jsonDocumentScannerCreator {}, nil
31
24
})
32
25
if err != nil {
33
26
panic (err )
34
27
}
35
28
}
36
29
37
- func jsonDocumentScannerFromParsed (conf * service.ParsedConfig ) (l * jsonDocumentScannerCreator , err error ) {
38
- l = & jsonDocumentScannerCreator {}
39
- if l .continueOnError , err = conf .FieldBool (sjsonFieldContinueOnError ); err != nil {
40
- return
41
- }
42
- return
43
- }
44
-
45
- type jsonDocumentScannerCreator struct {
46
- continueOnError bool
47
- }
30
+ type jsonDocumentScannerCreator struct {}
48
31
49
32
func (js * jsonDocumentScannerCreator ) Create (rdr io.ReadCloser , aFn service.AckFunc , details * service.ScannerSourceDetails ) (service.BatchScanner , error ) {
50
33
return service .AutoAggregateBatchScannerAcks (& jsonDocumentScanner {
51
- d : json .NewDecoder (rdr ),
52
- r : rdr ,
53
- continueOnError : js .continueOnError ,
34
+ d : json .NewDecoder (rdr ),
35
+ r : rdr ,
54
36
}, aFn ), nil
55
37
}
56
38
@@ -61,27 +43,21 @@ func (js *jsonDocumentScannerCreator) Close(context.Context) error {
61
43
type jsonDocumentScanner struct {
62
44
d * json.Decoder
63
45
r io.ReadCloser
64
-
65
- continueOnError bool
66
46
}
67
47
68
48
func (js * jsonDocumentScanner ) NextBatch (ctx context.Context ) (service.MessageBatch , error ) {
69
49
if js .r == nil {
70
50
return nil , io .EOF
71
51
}
72
52
73
- msg := service .NewMessage (nil )
74
-
75
53
var jsonDocObj any
76
-
77
54
if err := js .d .Decode (& jsonDocObj ); err != nil {
78
- msg .SetError (err )
79
- if errors .Is (err , io .EOF ) || ! js .continueOnError {
80
- return nil , err
81
- }
55
+ _ = js .r .Close ()
56
+ js .r = nil
57
+ return nil , err
82
58
}
83
59
84
- // Decode will determine whether a the jsonObj is of type map[string]interface{} or []interface{}
60
+ msg := service . NewMessage ( nil )
85
61
msg .SetStructuredMut (jsonDocObj )
86
62
87
63
return service.MessageBatch {msg }, nil
0 commit comments