{"action":"created","issue":{"url":"https://api.github.com/repos/Raizlabs/DBFlow/issues/627","repository_url":"https://api.github.com/repos/Raizlabs/DBFlow","labels_url":"https://api.github.com/repos/Raizlabs/DBFlow/issues/627/labels{/name}","comments_url":"https://api.github.com/repos/Raizlabs/DBFlow/issues/627/comments","events_url":"https://api.github.com/repos/Raizlabs/DBFlow/issues/627/events","html_url":"https://github.com/Raizlabs/DBFlow/issues/627","id":133199957,"number":627,"title":"java.lang.ClassCastException on Image Blob","user":{"login":"DiegoTavares","id":882795,"avatar_url":"https://avatars.githubusercontent.com/u/882795?v=3","gravatar_id":"","url":"https://api.github.com/users/DiegoTavares","html_url":"https://github.com/DiegoTavares","followers_url":"https://api.github.com/users/DiegoTavares/followers","following_url":"https://api.github.com/users/DiegoTavares/following{/other_user}","gists_url":"https://api.github.com/users/DiegoTavares/gists{/gist_id}","starred_url":"https://api.github.com/users/DiegoTavares/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DiegoTavares/subscriptions","organizations_url":"https://api.github.com/users/DiegoTavares/orgs","repos_url":"https://api.github.com/users/DiegoTavares/repos","events_url":"https://api.github.com/users/DiegoTavares/events{/privacy}","received_events_url":"https://api.github.com/users/DiegoTavares/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-02-12T10:03:40Z","updated_at":"2016-04-19T03:33:31Z","closed_at":"2016-04-19T03:33:31Z","body":"I'm getting the error: \r\n java.lang.ClassCastException: android.graphics.Bitmap cannot be cast to byte[]\r\nwhen trying to retrieve an element that has a blob element by Foreign Key Container.\r\n\r\nModel:\r\n\r\n```java\r\n@ModelContainer\r\n@Table(database = CoffeeDatabase.class)\r\npublic class User extends BaseModel implements UserInterface{\r\n\r\n    @PrimaryKey(autoincrement = true)\r\n    private long id;\r\n\r\n    @Column\r\n    @NotNull\r\n    private String name;\r\n\r\n    @Column\r\n    @NotNull\r\n    private String email;\r\n\r\n    @Column(typeConverter = ImageConverter.class)\r\n    public Bitmap image;\r\n    [...]\r\n}\r\n```\r\n\r\nHere is my image converter:\r\n\r\n```java\r\n@com.raizlabs.android.dbflow.annotation.TypeConverter\r\npublic class ImageConverter extends TypeConverter<Blob, Bitmap> {\r\n\r\n    @Override\r\n    public Blob getDBValue(Bitmap model) {\r\n        ByteArrayOutputStream baos = new ByteArrayOutputStream();\r\n        model.compress(Bitmap.CompressFormat.PNG, 0, baos);\r\n\r\n        return new Blob(baos.toByteArray());\r\n    }\r\n\r\n    @Override\r\n    public Bitmap getModelValue(Blob data) {\r\n        byte[] blob = data.getBlob();\r\n        return BitmapFactory.decodeByteArray(blob, 0, blob.length);\r\n    }\r\n}\r\n```\r\n\r\nThe exception is thrown when executing:\r\n\r\n```java\r\n        if(user == null && userForeignKeyContainer != null) {\r\n            user = userForeignKeyContainer.toModel();\r\n        }\r\n```\r\n\r\nThe generated user container \"toModel()\" function is calling getBlbValue(\"image\") which tries to cast the bitmap value to byte[].\r\n\r\nin User_Container.java:\r\n```java\r\n@Override\r\n  public final User toModel(ModelContainer<User, ?> modelContainer) {\r\n    User model = new User();\r\n    model.setId(modelContainer.getLngValue(\"id\"));\r\n    model.setName(modelContainer.getStringValue(\"name\"));\r\n    model.setEmail(modelContainer.getStringValue(\"email\"));\r\n    model.image = typeConverterImageConverter.getModelValue((com.raizlabs.android.dbflow.data.Blob) new Blob(modelContainer.getBlbValue(\"image\")));\r\n    return model;\r\n  }\r\n```\r\n\r\nIt seems that the converter is not being called."},"comment":{"url":"https://api.github.com/repos/Raizlabs/DBFlow/issues/comments/211712582","html_url":"https://github.com/Raizlabs/DBFlow/issues/627#issuecomment-211712582","issue_url":"https://api.github.com/repos/Raizlabs/DBFlow/issues/627","id":211712582,"user":{"login":"agrosner","id":2117859,"avatar_url":"https://avatars.githubusercontent.com/u/2117859?v=3","gravatar_id":"","url":"https://api.github.com/users/agrosner","html_url":"https://github.com/agrosner","followers_url":"https://api.github.com/users/agrosner/followers","following_url":"https://api.github.com/users/agrosner/following{/other_user}","gists_url":"https://api.github.com/users/agrosner/gists{/gist_id}","starred_url":"https://api.github.com/users/agrosner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agrosner/subscriptions","organizations_url":"https://api.github.com/users/agrosner/orgs","repos_url":"https://api.github.com/users/agrosner/repos","events_url":"https://api.github.com/users/agrosner/events{/privacy}","received_events_url":"https://api.github.com/users/agrosner/received_events","type":"User","site_admin":false},"created_at":"2016-04-19T03:33:31Z","updated_at":"2016-04-19T03:33:31Z","body":"should be fixed in a 3.0.0-beta4 :)"}}