Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to convert csv to json using unmarshal/marshal #1253

Closed
arickbro opened this issue Sep 7, 2021 · 2 comments
Closed

how to convert csv to json using unmarshal/marshal #1253

arickbro opened this issue Sep 7, 2021 · 2 comments

Comments

@arickbro
Copy link

arickbro commented Sep 7, 2021

I try to ingest a csv file using camel sftp connector , parse the csv and turn it to json using this configuration

{
	"connector.class":"org.apache.camel.kafkaconnector.sftp.CamelSftpSourceConnector",
	"topics":"sftp3",
	"tasks.max":"1",
	"key.converter":"org.apache.kafka.connect.converters.ByteArrayConverter",
	"value.converter":"org.apache.kafka.connect.storage.StringConverter",
	"errors.tolerance":"none",
	"camel.source.path.host":"10.0.2.111",
	"camel.source.path.port":"22",
	"camel.source.path.directoryName":"demos/simlink",
	"camel.source.path.fileName":"bgp.txt",
	"camel.source.endpoint.recursive":"false",
	"camel.source.endpoint.username":"xxx",
	"camel.source.endpoint.password":"xxxx",
	"camel.source.endpoint.noop":"true",
	"transforms":"RemoteTransformer",
	"transforms.RemoteTransformer.type":"org.apache.camel.kafkaconnector.RemoteFileTransforms",
	"camel.source.endpoint.idempotentKey":"${file:name}-${file:modified}",
	"camel.remove.headers.pattern":"Camel*",
	"camel.source.marshal":"json-gson",
	"camel.source.unmarshal":"csv"
}

unmarshal=csv work just fine, I can see the java object on kafka.
but if I combine it with marshal=json-gson, I got this error

 (org.apache.camel.processor.errorhandler.DefaultErrorHandler)
java.lang.IllegalStateException: IOException reading next record: java.io.IOException: (line 1) invalid char between encapsulated token and delimiter
        at org.apache.commons.csv.CSVParser$CSVRecordIterator.getNextRecord(CSVParser.java:149)
        at org.apache.commons.csv.CSVParser$CSVRecordIterator.hasNext(CSVParser.java:159)

could someone give me advise on this ?

@oscerd
Copy link
Contributor

oscerd commented Sep 7, 2021

You cannot have unmarshal and marshal in the same connector configuration. If you want to do this you'll need to create your own SMT to transform from csv to JSON.

@arickbro
Copy link
Author

arickbro commented Sep 7, 2021

thanks, I will close this issue

@arickbro arickbro closed this as completed Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants