title: Expression Value in Jasper Report: “Cannot cast from ByteArrayInputStream to String” error
body: <p>I am trying to convert an encoded tag in an xml to image and then convert into PDF using Java and <em>Jaspersoft Studio</em>. </p>
  
  <p><strong>NOTE :</strong> When I am previewing in Jasper studio I am getting proper display image but getting the above error while running it using Java main method.
  Motive of the code is to fetch the tag from xml and convert it to pdf with image. </p>
  
  <p>I am using <em>JasperReports 6.4.0</em>. While previewing from <em>Jaspersoft Studio</em> image is getting displayed properly and jrxml file is getting compiled too. But while running using main method in Java, I am getting error. </p>
  
  <p>Below is the jrxml file I am using. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="ImageDS" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"&gt;
      &lt;queryString language="xPath"&gt;
          &lt;![CDATA[/Data/ListOfIdeaCafEntryFormIio/IdeaCafEntryFormBc]]&gt;
      &lt;/queryString&gt;
      &lt;field name="Photo" class="java.lang.String"&gt;
          &lt;fieldDescription&gt;&lt;![CDATA[Photo]]&gt;&lt;/fieldDescription&gt;
      &lt;/field&gt;
      &lt;group name="Photo"&gt;
          &lt;groupExpression&gt;&lt;![CDATA[$F{Photo}]]&gt;&lt;/groupExpression&gt;
      &lt;/group&gt;
      &lt;columnHeader&gt;
          &lt;band height="61" splitType="Stretch"&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="206" y="0" width="100" height="30"/&gt;
                  &lt;text&gt;&lt;![CDATA[Photo]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
          &lt;/band&gt;
      &lt;/columnHeader&gt;
      &lt;detail&gt;
          &lt;band height="125" splitType="Stretch"&gt;
              &lt;image&gt;
                  &lt;reportElement x="205" y="52" width="50" height="50"/&gt;
                  &lt;imageExpression&gt;&lt;![CDATA[new java.io.ByteArrayInputStream(org.apache.commons.codec.binary.Base64.decodeBase64($F{Photo}.getBytes()))]]&gt;&lt;/imageExpression&gt;
              &lt;/image&gt;
          &lt;/band&gt;
      &lt;/detail&gt;
  &lt;/jasperReport&gt;
  </code></pre>
  
  <p>Java Code used to generate PDF :</p>
  
  <pre><code>public class Java8Base64Image {
  
      public static void main(String[] args) {
          BaseDao dao = new BaseDao();
  
          Connection connection = dao.getConnection();
          try {
              String reportName = "C:/..../MyReports/ImageDS";
              Map&lt;String, Object&gt; parameters = new HashMap&lt;String, Object&gt;();
  
              JasperCompileManager.compileReportToFile(reportName + ".jrxml");
              JasperPrint print = JasperFillManager.fillReport(reportName + ".jasper", parameters, connection);
              // exports report to pdf
              JRExporter exporter = new JRPdfExporter();
              exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
              exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, new FileOutputStream(reportName + ".pdf"));
              exporter.exportReport();
          } catch (Exception e) {
              throw new RuntimeException("It's not possible to generate the pdf report.", e);
          } finally {
              if (connection != null) {
                  try { connection.close(); } catch (Exception e) {}
              }
          }
      }
  }
  </code></pre>
  
  <p>XML with image:</p>
  
  <pre><code>&lt;Photo&gt;/9j/..../OiiiQon/9k=&lt;/Photo&gt;
  </code></pre>
  
  <p>The error I got</p>
  
  <pre><code>    Error is : Caused by: net.sf.jasperreports.engine.JRException: 
  Errors were encountered when compiling report expressions class file: 
  1. Cannot cast from ByteArrayInputStream to String value = (java.lang.String)(new java.io.ByteArrayInputStream(org.apache.commons.codec.binary‌​.Base64.decodeBase64‌​(((java.lang.String)‌​field_Photo.getValue‌​()).getBytes()))); //$JR_EXPR_ID=11$
  </code></pre>