title: Converting byte array to Json giving avro Schema as input is giving an error
body: <p>I have a simple JSON  </p>
  
  <pre><code>  String jsonPayload = "{\"empid\": \"6\",\"empname\": \"Saurabh\",\"address\": \"home\"}";
      jsonPayload.getBytes();
  </code></pre>
  
  <p>I created avro schema </p>
  
  <pre><code>{"namespace": "sample.namespace",
   "type": "record",
   "name": "Employee",
   "fields": [
       {"name": "empid", "type": "string"},
       {"name": "empname",  "type": "string"},
       {"name": "address", "type": "string"}
   ]
  }
  </code></pre>
  
  <p>When I try to compare them I get an error 
  Exception :</p>
  
  <pre><code>org.apache.avro.AvroRuntimeException: Malformed data. Length is negative: -62
      at org.apache.avro.io.BinaryDecoder.doReadBytes(BinaryDecoder.java:336)
      at org.apache.avro.io.BinaryDecoder.readString(BinaryDecoder.java:263)
      at org.apache.avro.io.ResolvingDecoder.readString(ResolvingDecoder.java:201)
      at org.apache.avro.generic.GenericDatumReader.readString(GenericDatumReader.java:430)
      at org.apache.avro.generic.GenericDatumReader.readString(GenericDatumReader.java:422)
      at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:180)
      at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:152)
      at org.apache.avro.generic.GenericDatumReader.readField(GenericDatumReader.java:240)
      at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:230)
      at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:174)
      at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:152)
      at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:144)
  </code></pre>
  
  <p>Looks like there is problem with String and Charsequence identification. Not able to identify exact problem</p>
  
  <p>bytearraytojson converter method code</p>
  
  <pre><code>public String byteArrayToJson(byte[] avro, Schema schema) throws IOException {
          boolean pretty = false;
          GenericDatumReader&lt;GenericRecord&gt; reader = null;
          JsonEncoder encoder = null;
          ByteArrayOutputStream output = null;
          try {
  
              reader = new GenericDatumReader&lt;GenericRecord&gt;(schema);
              InputStream input = new ByteArrayInputStream(avro);
              output = new ByteArrayOutputStream();
              DatumWriter&lt;GenericRecord&gt; writer = new GenericDatumWriter&lt;GenericRecord&gt;(schema);
              encoder = EncoderFactory.get().jsonEncoder(schema, output, pretty);
              Decoder decoder = DecoderFactory.get().binaryDecoder(input, null);
              GenericRecord datum;
              while (true) {
                  try {
                      datum = reader.read(null, decoder);
                  } catch (EOFException eofe) {
                      break;
                  }
                  writer.write(datum, encoder);
              }
              encoder.flush();
              output.flush();
              return new String(output.toByteArray());
          } finally {
              try {
                  if (output != null) output.close();
              } catch (Exception e) {
              }
          }
      }
  </code></pre>