I have troubles reading/unmarshalling multidimensional arrays with Morphia.
The following class:
@Entity
class A {
double[][] matrix;
}
is properly marshalled and stored in mongodb, but when reading it I get an exception that the double[][] can not be constructed. I've tried to use a custom TypeConverter but it is not getting invoked for such types. Similar issues I get when using a member like this:
List<double[]> matrix;
I did not find any annotations that could help morphia figure out what type is expected in the array. I suspect this is not supported yet. Any suggestions ?
Thanks in advance.
I haven't used multi-dimensional arrays with Morphia yet, so I can't say much about that. However, I've done the following for unsupported data types (like BigDecimal):
My code looks something like this:
@Transient
private BigDecimal salary;
private String salaryString;
@PrePersist
public void prePersist(){
if(salary != null){
this.salary = this.salary.setScale(2, BigDecimal.ROUND_HALF_UP);
salaryString = this.salary.toString();
}
}
@PostLoad
public void postLoad(){
if(salary != null){
this.salary = this.salary.setScale(2, BigDecimal.ROUND_HALF_UP);
this.salary = new BigDecimal(salaryString);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With