Storage of multidimensional arrays with Morphia

I'm having trouble reading / unpacking multidimensional arrays using Morphia.

Next class:

@Entity
class A {

  double[][] matrix;
}

is sorted and stored correctly in mongodb, but when reading, I get an exception that double [] [] cannot be constructed. I tried using a custom TypeConverter, but it will not be called for such types. Similar problems occur when using this element:

List<double[]> matrix;

I did not find any annotations that could help morphia figure out which type is expected in the array. I suspect this is not yet supported. Any suggestions?

Thanks in advance.

+5
source share
1 answer

Morphia, . , (, BigDecimal):

  • .
  • Serialize/unserialize @PrePersist @PostLoad

:

@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);
  }
}
+1

All Articles