JsonParseException: Invalid UTF-8 middle byte 0x2d
<p>I have a JSON String from which I am making a <code>InputStream object</code> as shown below and then I am making a <code>GenericRecord</code> object as I am trying to serialize my JSON object to Avro schema.</p>

<pre><code>InputStream input = new ByteArrayInputStream(jsonString.getBytes());
DataInputStream din = new DataInputStream(input);

Decoder decoder = DecoderFactory.get().jsonDecoder(schema, din);

DatumReader&lt;GenericRecord&gt; reader = new GenericDatumReader&lt;GenericRecord&gt;(schema);
// below line is throwing exception
GenericRecord datum = reader.read(null, decoder);   
</code></pre>

<p>Below is the exception I am getting:</p>

<pre><code>org.codehaus.jackson.JsonParseException: Invalid UTF-8 middle byte 0x2d at [Source: java.io.DataInputStream@562aee31; line: 1, column: 74]
</code></pre>

<p>And here is the actual JSON string on which this exception is happening:</p>

<pre><code>{"name":"car_test","attr_value":"2006|Renault|Megane II Coupé-Cabriolet|null|null|null|null|0|Wed Feb 03 10:00:59 GMT-07:00 2016|1|77|null|null|null|null","data_id":900}
</code></pre>

<p>I did some research and found out that I need to use <code>ByteArrayInputStream</code> with UTF-8 encodings as shown below:</p>

<pre><code>InputStream input = new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8.displayName()));
</code></pre>

<p>But my question is what is the reason of this exception? And why it is happening on my above JSON String? I am just trying to understand why this exception is happening on my above JSON String. And using <code>UTF-8</code> is the right fix for this?</p>

<p>What does this error means <code>Invalid UTF-8 middle byte 0x2d</code>?</p>