You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by Franz Paul Forsthofer <em...@googlemail.com> on 2015/06/25 14:35:31 UTC
Encoding problems in jsonpath - https://issues.apache.org/jira/browse/CAMEL-8905
Hello,
i detected three different encoding problems in jsonpath. I reported
them in https://issues.apache.org/jira/browse/CAMEL-8905 and attached
also a patch.
Can somebody of you have a look at the patch? I actually can do the
commit myself. However, in this case I would like to have a reviewer.
I propose in the patch to replace the code in JsonEngine.java
public Object read(Exchange exchange) throws IOException,
InvalidPayloadException {
Object json = exchange.getIn().getBody();
if (json instanceof GenericFile) {
try {
json =
GenericFileConverter.genericFileToInputStream((GenericFile<?>) json,
exchange);
} catch (NoTypeConversionAvailableException e) {
json = ((WrappedFile<?>) json).getFile();
}
} else if (json instanceof WrappedFile) {
json = ((WrappedFile<?>) json).getFile();
}
// the message body type should use the suitable read method
if (json instanceof String) {
String str = (String) json;
return path.read(str, configuration);
} else if (json instanceof InputStream) {
InputStream is = (InputStream) json;
return path.read(is,
Charset.defaultCharset().displayName(), configuration);
} else if (json instanceof File) {
File file = (File) json;
return path.read(file, configuration);
} else if (json instanceof URL) {
URL url = (URL) json;
return path.read(url, configuration);
}
// fallback as input stream
InputStream is = exchange.getIn().getMandatoryBody(InputStream.class);
return path.read(is);
}
by the following code
public Object read(Exchange exchange) throws IOException,
InvalidPayloadException {
Object json = exchange.getIn().getBody();
if (json instanceof GenericFile) {
GenericFile<?> genericFile = (GenericFile<?>) json;
if (genericFile.getCharset() != null) {
// special treatment for generic file with charset
InputStream inputStream;
try {
inputStream =
GenericFileConverter.genericFileToInputStream((GenericFile<?>) json,
exchange);
} catch (NoTypeConversionAvailableException e) {
// cannot happen
throw new IllegalStateException(e);
}
// the generic file converter converts the encoding to
the platform default encoding, therefore we can use the platform
default encoding
return path.read(inputStream,
Charset.defaultCharset().name(), configuration);
}
}
if (json instanceof String) {
String str = (String) json;
return path.read(str, configuration);
} else {
InputStream is =
exchange.getIn().getMandatoryBody(InputStream.class);
JsonStream jsonStream = new JsonStream(is);
return path.read(jsonStream,
jsonStream.getEncoding().name(), configuration);
}
}
JsonStream determines the encoding of the json document according to
the chapter "3. Encoding" of the JSON spec
https://www.ietf.org/rfc/rfc4627.txt or according to its BOM.
Best Regards Franz