gpt4 book ai didi

java - 使用提供的 json 字符串创建模型

转载 作者:太空宇宙 更新时间:2023-11-04 10:07:02 25 4
gpt4 key购买 nike

我想在 Spring Boot 中使用以下 json 字符串创建模型。

{
"name": "inox",
"seatInfo": {
"A": {
"numberOfSeats": 10,
"aisleSeats": [
0,
5,
6,
9
]
},
"B": {
"numberOfSeats": 15,
"aisleSeats": [
0,
5,
6,
9
]
},
"D": {
"numberOfSeats": 20,
"aisleSeats": [
0,
5,
6,
9
]
}
}
}

到目前为止我已经这样做了。

 import java.util.Map;
import javax.persistence.*;

@Entity
public class Screen {

@Id
@GeneratedValue
private Long id;
private String name;
private Map<String, RowInfo> seatInfo;

//getter and setters
}


import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Arrays;

@Entity
public class RowInfo {

@Id
@GeneratedValue
private Long id;
private int numberOfSeats;
private Integer aisleSeats[];

//getters and setters
}

应用程序启动时出现以下异常。

嵌套异常是org.hibernate.MappingException:无法确定类型:java.util.Map,表:屏幕,列:[org.hibernate.mapping.Column(seat_info)]

最佳答案

将 Map 接口(interface)更改为 HashMap 类型(或您喜欢的类型)。

@Entity
public class Screen {

@Id
@GeneratedValue
private Long id;
private String name;
private HashMap<String, RowInfo> seatInfo;

//getter and setters
}


import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Arrays;

@Entity
public class RowInfo {

@Id
@GeneratedValue
private Long id;
private int numberOfSeats;
private Integer aisleSeats[];

//getters and setters
}

关于java - 使用提供的 json 字符串创建模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52790474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com