-
Notifications
You must be signed in to change notification settings - Fork 303
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Im getting the following error when im query the entity that is using an converter:
io.objectbox.exception.DbException: Entity is expected to have this constructor: Group(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLjava/lang/String;ZZZZL[J;)V
The constructor:
public Group(long id, String ..., String ..., String ..., boolean ..., String ...,
boolean ..., boolean ..., boolean ..., boolean ..., long[] deviceIds)
The Entity converter usage:
@Convert(converter = DeviceIdConverter.class, dbType = String.class)
private long[] deviceIds;
The Converter Class:
public class DeviceIdConverter implements PropertyConverter<long[], String> {
private static final ByteString SEMICOLON = ByteString.decodeBase64(";");
@Override
public long[] convertToEntityProperty(String s) {
if (s == null) {
return new long[0];
}
try {
long[] ids = new long[0];
Buffer buffer = new Buffer();
buffer.writeUtf8(s);
long index;
while ((index = buffer.indexOf(SEMICOLON)) != -1) {
ids = add(Long.parseLong(buffer.readUtf8(index - 1)), ids);
}
return ids;
} catch (IOException io) {
io.printStackTrace();
return new long[0];
}
}
public long[] add(long id, long[] values) {
long[] anotherArray = new long[values.length + 1];
System.arraycopy(values, 0, anotherArray, 0, values.length);
anotherArray[values.length] = id;
return anotherArray;
}
@Override
public String convertToDatabaseValue(long[] integers) {
Buffer buffer = new Buffer();
for (long value : integers) {
buffer.write(SEMICOLON);
buffer.writeUtf8(String.valueOf(value));
}
return buffer.toString();
}
}
markmooibroek, rootandy, LewJun, azizkayumov, creati8e and 4 more
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request