Dear Camel developers.
I have tested json marshaling / unmarshaling with gson library,
and found there was charset assignment missing
at org.apache.camel.component.gson.GsonDataFormat.java
in Camel version 2.12.0
The marshal and unmarshal methods should create a stream writer or reader
with the charset "UTF-8”.
If not, Gson fails when unmarshaling non ascii character json stream like
{“name”: “차”}.
This is the exception.
com.google.gson.JsonSyntaxException:
com.google.gson.stream.MalformedJsonException: Unterminated string at line
1 column 14
at com.google.gson.Gson.fromJson(Gson.java:818)
at com.google.gson.Gson.fromJson(Gson.java:741)
at
org.apache.camel.component.gson.GsonDataFormat.unmarshal(GsonDataFormat.java
:105)
…
So I suggest that GsonDataFormat.java be modified to have the charset
assignment part like below.
…
public void marshal(Exchange exchange, Object graph,
OutputStream stream) throws Exception {
BufferedWriter writer = IOHelper.buffered(new
OutputStreamWriter(stream, "UTF-8")); // <- modify here, please
gsontoJson(graph, writer);
writer.close();
}
…
public Object unmarshal(Exchange exchange, InputStream stream)
throws Exception {
BufferedReader reader = IOHelper.buffered(new
InputStreamReader(stream, "UTF-8")); // <- modify here, please
Object result = gson.fromJson(reader,
this.unmarshalType);
reader.close();
return result;
}
See https://sites.google.com/site/gson/streaming
Maybe I have misunderstood this, but check it please.
Thanks.