As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
getTypedObject returns null if the entity contains an integer field
R
Ruben
started a topic
over 8 years ago
Hello guys,
I have a problem with getTypedObject returning null here:
BookCloud c = this.book.getTypedObject(BookCloud.class);
The problem only appears when I add an integer or float field to my class, If I remove that field then works fine. I also can see the correct values in the kinveyreference "obj" field retrieved.
Here is the BookCloud class with an integer "pages" field added:
public class BookCloud extends extends GenericJson {
@Key private String title;
@Key private String edition;
@Key private int pages;
public BookCloud() {
}
Can you help me?
Thanks in advance.
Best Answer
K
Kinvey Support
said
over 8 years ago
Hi,
I was able to reproduce the issue using a similar code snippet and I got following error:
I/System.out﹕ unable to instantiate class!
W/System.err﹕ java.lang.IllegalArgumentException: field <Class>.status has type int, got java.math.BigDecimal
I was able to solve this error by changing the declaration of the field to Number instead of int/Integer.
As I said before, I've checked that removing the next field from BookCloud class works fine. Also checked that with float fields fails too, looks like only string and booleans works fine.
I was able to reproduce the issue using a similar code snippet and I got following error:
I/System.out﹕ unable to instantiate class!
W/System.err﹕ java.lang.IllegalArgumentException: field <Class>.status has type int, got java.math.BigDecimal
I was able to solve this error by changing the declaration of the field to Number instead of int/Integer.
Let me know if this works for you.
Regards,
Wani
R
Ruben
said
over 8 years ago
Hi Wani,
For me it makes no sense to have to change all float and int fields of my entities to Number but just tested and works fine.
Many thanks,
Ruben.
Damien Bell
said
over 8 years ago
Ruben:
To give you some insight, we do have this flagged as a bug on our end and it will get attention going forward. For now using Number rather than the other primitive types and wrapper classes is inconvenient and we apologize that this is the case.
Ruben
Hello guys,
I have a problem with getTypedObject returning null here:
BookCloud c = this.book.getTypedObject(BookCloud.class);
The problem only appears when I add an integer or float field to my class, If I remove that field then works fine. I also can see the correct values in the kinveyreference "obj" field retrieved.
Here is the BookCloud class with an integer "pages" field added:
public class BookCloud extends extends GenericJson {
@Key private String title;
@Key private String edition;
@Key private int pages;
public BookCloud() {
}
Can you help me?
Thanks in advance.
Hi,
I was able to reproduce the issue using a similar code snippet and I got following error:
I was able to solve this error by changing the declaration of the field to Number instead of int/Integer.
Let me know if this works for you.
Regards,
Wani
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstKinvey Support
Hi Ruben,
I need some more details about this so that I can help you find a solution.
If possible, please share
Ruben
Hi Wani,
First, here is the library class which contains an array of librarybooks:
public class LibraryCloud extends GenericJson {
@Key private String name;
@Key private ArrayList<LibraryBookCloud> librarybooks = new ArrayList<LibraryBookCloud>();
public LibraryCloud() {
}
@Override public Class<LibraryEntity> getEntityClass() { return LibraryEntity.class; }
@Override public String[] getResolves() { return new String[]{"librarybooks.book"}; }
public String getName() { return name; }
}
Second, the librarybook class containing the KinveyReference to the book
public class LibraryBookCloud extends GenericJson {
@Key private String state;
@Key private KinveyReference book = new KinveyReference();
public LibraryBookCloud() {
}
public String getState() { return state; }
public void setBook(BookEntity book){
this.book = new KinveyReference(book.getEntityCloud().getEntityName(), book.getEntityCloud().get("_id").toString());
}
public BookCloud getBook() {
BookCloud c = this.book.getTypedObject(BookCloud.class);
return c;
}
}
Finally, here is the call to the backend:
public void Get(LibraryCloud lc, ArrayList<QueryCondition> query) {
AsyncAppData<LibraryCloud> mData = mClient.appData("Librarys", LibraryCloud.class);
mData.get(getKinveyQuery(query), lc.getResolves(), new KinveyListCallback<LibraryCloud>() {
@Override
public void onSuccess(LibraryCloud[] r) {
ArrayList<LibraryCloud> entities = new ArrayList<LibraryCloud>();
for (LibraryCloud e : r)
entities.add(e);
Log.d(App.LOG, r.length + " cloud <Libraries> retrieved");
if (dsi!=null) dsi.onCloudGetReceived("Libraries", entities);
}
@Override
public void onFailure(Throwable e) {
Log.e(App.LOG, "failed to get cloud data <Libraries>", e);
if (dsi!=null) dsi.onCloudGetFailed();
}
});
}
The backend retuns the correct data but in the LibraryBookCloud the next line sets BookCloud c to null...
BookCloud c = this.book.getTypedObject(BookCloud.class);
...despite I can see the _obj within the book object containing the correct data for the book:
{"_collection":"Books","_id":"b80152b13311485aa7d5a8e0d505c990","_type":"KinveyRef","_obj":{"_id":"b80152b13311485aa7d5a8e0d505c990","author":{"country":"Country1","name":"Author1"},"edition":"Edition1.1","pages":123,"title":"Title1","_acl":{"creator":"548c437944d53dc54300050b"},"_kmd":{"lmt":"2015-04-17T17:21:57.967Z","ect":"2015-04-17T17:21:57.967Z"}}}
As I said before, I've checked that removing the next field from BookCloud class works fine. Also checked that with float fields fails too, looks like only string and booleans works fine.
@Key private int pages;
Thanks for your time,
Ruben.
Ruben
Hi Wani, attached you can find the details.
Thanks for your time.
Kinvey Support
Hi,
I was able to reproduce the issue using a similar code snippet and I got following error:
I was able to solve this error by changing the declaration of the field to Number instead of int/Integer.
Let me know if this works for you.
Regards,
Wani
Ruben
Hi Wani,
For me it makes no sense to have to change all float and int fields of my entities to Number but just tested and works fine.
Many thanks,
Ruben.
Damien Bell
Ruben:
To give you some insight, we do have this flagged as a bug on our end and it will get attention going forward. For now using Number rather than the other primitive types and wrapper classes is inconvenient and we apologize that this is the case.
Thanks,
-
Can I add KinveyReferences and other custom Arrays to the User entity?
-
How can I use custom enums within my Entity?
-
Linking an image does not save with LinkedData
-
How can I get all records saved by the current user?
-
Why don't all users see the same data when querying?
-
Retrieving related file from datastore collection - continued
-
Problem implementing sign up / login
-
Can Android API be used for Java?
-
I'm not receiving push notifications
-
It is impossible to receive object according to the link
See all 259 topics