0

当我尝试使用房间数据库保存对象时,数据插入成功。在检索数据时,对象内部的一个值,它是一个对象,被检索为数组。将数组转换回对象不起作用。根对象内的其他字符串和整数值已正确检索。

保存对象:

[[F@6c173ab

检索对象:

[[0.0066505815, 0.00605235, 0.0044598486, -0.011793762, 0.0069282507, -0.059397057, -0.058320906, 0.17123938, -0.019021105, -0.1037456, 0.0018062548, -0.005069571, 0.0035884415, 0.0017127255, 0.004238736, -0.058450952, -0.007079399, -0.010851874, 9.1687456E- 4, 0.013117686, 0.26496187, -0.056337364, 0.054294083, 0.0023271786, 0.19248551, -0.031670928, 0.004658082, -0.042408537, -0.08871324, -0.13611381, 0.0048175915, 0.060110737, -0.05661096, -0.004599247, 0.02567487, -0.14492176, 0.41225138, 0.037969578, -0.0060184584 , 0.16407079, -0.007605861, -0.004265492, -0.0011223844, 0.006605887, -0.008077469, 0.0015253898, -0.10189122, 0.050602783, 0.0058309403, 0.057144053, 0.07865115, -0.0022470118, 0.005851626, -0.001395651, -0.061264377, -0.007627005, -0.1531251, -8.3948084E -4、0.02980912、-0.002113619、-0.0018161217、-0.10022795、0.12291724、0.07126657、1.6772193E-4, 0.022098381, 0.0026675903, 0.03227209, 0.011782837, 0.006000733, 0.009471676, 0.036371186, -0.23033214, -0.002258695, 0.039965842, -0.00845738, 0.0025282402, 6.5926113E-4, 0.03005817, 0.032968543, 0.003514709, 0.03701494, -0.0047574765, 0.0067672534, 0.08913908, 0.0014652971, 0.009258712, -0.03202012, -0.024361957, -0.10464151, -0.033407286, -0.0027610548, -0.00944446, -0.0024300436, -0.0232218, 0.0094572455, 0.018079767, 0.23599343, -0.0063236416, 0.034273528, 5.9618044E-4, 0.010737699, 0.008162582, 0.0025107688, 0.007046912, 0.0026148462, -6.691977E-4, 0.0018003252, -0.017509019, 0.0071865367, 0.17709938, -0.0027926106, 0.0041772844, 0.24446069, 0.0035891477, 0.090311974, -0.005678741, 0.002527207, -0.043642007, 0.013362809, -0.10237697, 0.004665849, 0.029806657, 8.510543 E-4, 0.008034529, 0.0037261287, 0.0016963077, -0.0065462743,0.0014083247, -0.09163139, -7.1395264E-4, 0.0034422423, 2.2180262E-4, -0.050950024, 0.052165035, -6.5167714E-4, 0.09660987, 0.059556033, 0.0011484445, 0.0048205433, 0.016215535, -0.0074894307, -4.8624526E-4, 0.09030299, -0.031675506, 0.035420638, 0.00863125, 0.0062305178, -2.9943243E-4, 0.017759249, -0.007217323, -0.17156895, -0.08075601, 0.013375583, -0.0057125236, 0.0019819727, 0.0045942706, -9.6630485E-4, -0.0056799883, -0.001163379, 0.026658272, 0.0045382543 , 0.0053815856, -0.0019246427, -0.0020221453, -0.0036204413, -0.016369255, -0.07884872, 0.0012176841, -0.0077565406, 0.08828778, -0.18202521, 0.0031140386, -0.013568612, 0.03727499, 0.0029328368, -0.009444142, 0.061891776, -0.0021317177, 7.041842E-5, -0.06919885, -0.022822084, -0.009733031, 0.0038881213, 0.2372824, 0.15371381, -0.0267819, -0.048720658, 0.029161548, -0.2631695977, 0.50.0020684062]]

这是我使用的类型转换器

@TypeConverter
public static String fromRecognition(SimilarityClassifier.Recognition recognition) {
    if (recognition == null) {
        return (null);
    }
    Gson gson = new Gson();
    Type type = new TypeToken<SimilarityClassifier.Recognition>() {
    }.getType();
    String json = gson.toJson(recognition, type);
    return json;
}

@TypeConverter
public static SimilarityClassifier.Recognition toRecognition(String recognitionString) {
    if (recognitionString == null) {
        return (null);
    }
    Gson gson = new Gson();
    Type type = new TypeToken<SimilarityClassifier.Recognition>() {
    }.getType();
    SimilarityClassifier.Recognition recognition = gson.fromJson(recognitionString, type);
    return recognition;
}

数据库中的列给出为

@ColumnInfo(name = "record")
@TypeConverters(Converters.class)
private SimilarityClassifier.Recognition record;




public SimilarityClassifier.Recognition getRecord() {
    return record;
}

public void setRecord(SimilarityClassifier.Recognition record) {
    this.record = record;
}

相似性分类器.识别如下

公共类识别{

private final String id;
private final String title;
private final Float distance;
private Object extra;

private RectF location;
private Integer color;
private Bitmap crop;

public Recognition(
        final String id, final String title, final Float distance, final RectF location) {
    this.id = id;
    this.title = title;
    this.distance = distance;
    this.location = location;
    this.color = null;
    this.extra = null;
    this.crop = null;
}

public String getId() {
    return id;
}

public String getTitle() {
    return title;
}

public Float getDistance() {
    return distance;
}

public RectF getLocation() {
    return new RectF(location);
}

public Bitmap getCrop() {
    return this.crop;
}

public Integer getColor() {
    return this.color;
}

public Object getExtra() {
    return this.extra;
}


public void setExtra(Object extra) {
    this.extra = extra;
}

public void setColor(Integer color) {
    this.color = color;
}

public void setLocation(RectF location) {
    this.location = location;
}

public void setCrop(Bitmap crop) {
    this.crop = crop;
}


@Override
public String toString() {
    String resultString = "";
    if (id != null) {
        resultString += "[" + id + "] ";
    }

    if (title != null) {
        resultString += title + " ";
    }

    if (distance != null) {
        resultString += String.format("(%.1f%%) ", distance * 100.0f);
    }

    if (location != null) {
        resultString += location + " ";
    }

    return resultString.trim();
}

如果其他人遇到这个问题,请帮助

4

0 回答 0