I'm trying to convert a JSON back to an Object when this error occurs. How can i get rid of this error? This is the class whose object i'm trying to get after converting from JSON:
class Recognition implements Serializable {
private final String id;
private final String title;
private final Float distance;
private Object extra;
private RectF location;
private Integer color;
private Bitmap crop;
public Recognition(
final String id, final String title, final Float distance, final RectF location) {
this.id = id;
this.title = title;
this.distance = distance;
this.location = location;
this.color = null;
this.extra = null;
this.crop = null;
}
public void setExtra(Object extra) {
this.extra = extra;
}
public Object getExtra() {
return this.extra;
}
public void setColor(Integer color) {
this.color = color;
}
public String getId() {
return id;
}
public String getTitle() {
return title;
}
public Float getDistance() {
return distance;
}
public RectF getLocation() {
return new RectF(location);
}
public void setLocation(RectF location) {
this.location = location;
}
public Integer getColor() {
return this.color;
}
public void setCrop(Bitmap crop) {
this.crop = crop;
}
public Bitmap getCrop() {
return this.crop;
}
@Override
public String toString() {
String resultString = "";
if (id != null) {
resultString += "[" + id + "] ";
}
if (title != null) {
resultString += title + " ";
}
if (distance != null) {
resultString += String.format("(%.1f%%) ", distance * 100.0f);
}
if (location != null) {
resultString += location + " ";
}
if (color != null) {
resultString += color + " ";
}
if (extra != null) {
resultString += extra + " ";
}
if (crop != null) {
resultString += encodeToBase64(crop, Bitmap.CompressFormat.JPEG, 100) + " ";
}
return resultString.trim();
}
public static String encodeToBase64(Bitmap image, Bitmap.CompressFormat compressFormat, int quality)
{
ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
image.compress(compressFormat, quality, byteArrayOS);
return Base64.encodeToString(byteArrayOS.toByteArray(), Base64.DEFAULT);
}
public static Bitmap decodeBase64(String input)
{
byte[] decodedBytes = Base64.decode(input, 0);
return BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
}
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
crop.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
out.writeInt(byteArray.length);
out.write(byteArray);
}
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
int bufferLength = in.readInt();
byte[] byteArray = new byte[bufferLength];
int pos = 0;
do {
int read = in.read(byteArray, pos, bufferLength - pos);
if (read != -1) {
pos += read;
} else {
break;
}
} while (pos < bufferLength);
crop = BitmapFactory.decodeByteArray(byteArray, 0, bufferLength);
}
}
What I think is that there might be some issue in the constructor or in conversion of bitmap. But i'm not sure. So if you hava any solution. Please let me know.