AnsweredAssumed Answered

MapR DB OJAI - custom class support differentiation in insert and mutate operations

Question asked by ondrad on Nov 7, 2017
Latest reply on Nov 13, 2017 by cathy

Hello,

I'm facing strange errors with updating JSON document in MapR DB (5.2.2). My classes look like:

class A {
private String X;
private String Y;
private List<B> bees;
}
class B {
private String foo;
private String bar;
}

 

Following code works as expected:

Document document = MapRDB.newDocument(A);
Table.insert(document);

But if I want to replace property bees in class/document A with:

List<B> list = new ArrayList<B>();
list.add(new B());
DocumentMutation dm = MapRDB.newMutation().setOrReplace("bees", list);
Table.update(a._id, dm);

it crashes with:

org.ojai.exceptions.TypeException: Unsupported object type of class: class my.domain.B
    at com.mapr.db.rowcol.DBValueBuilderBase.initFromObjectType(DBValueBuilderBase.java:144) ~[maprdb-5.2.2.201710021430-mapr.jar:5.2.2.201710021430-mapr]
    at com.mapr.db.rowcol.DBValueBuilderImpl.initFromObject(DBValueBuilderImpl.java:169) ~[maprdb-5.2.2.201710021430-mapr.jar:5.2.2.201710021430-mapr]
    at com.mapr.db.rowcol.DBValueBuilderImpl.initFrom(DBValueBuilderImpl.java:143) ~[maprdb-5.2.2.201710021430-mapr.jar:5.2.2.201710021430-mapr]
    at com.mapr.db.rowcol.MutationImpl.setOrReplace(MutationImpl.java:445) ~[maprdb-5.2.2.201710021430-mapr.jar:5.2.2.201710021430-mapr]
    at com.mapr.db.rowcol.MutationImpl.setOrReplace(MutationImpl.java:440) ~[maprdb-5.2.2.201710021430-mapr.jar:5.2.2.201710021430-mapr]

Following scenario works only if class B is primitive or String. Based on documentation all classes should supported:

DocumentMutation setOrReplace(FieldPath path, List<? extends Object> list)
Sets or replaces the field at the given FieldPath to the specified List.
Parameters:
path - path of the field that needs to be updated
list - The new value to set at the FieldPath

Is this some undocumented limitation or is it bug?

 

PS

temporary workaround is to create List with ojai Document class, but this is at least ugly (e.g. all lists with custom classes needs to be manually converted)

Outcomes