Java 显示所需的json dto类
创建了一个dto类,通过服务jsonschema2pojo.org/处理json。 结果是一个包含其他类的类,例如:Java 显示所需的json dto类,java,json,spring,dto,Java,Json,Spring,Dto,创建了一个dto类,通过服务jsonschema2pojo.org/处理json。 结果是一个包含其他类的类,例如: public class GeneralExmp{ private Strig name; // GetAndSet public class Exmp2{ private Strig id; private Map<String, Object> additionalProperties = new HashMap<String, Object&g
public class GeneralExmp{
private Strig name;
// GetAndSet
public class Exmp2{
private Strig id;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
// GetAndSet
}
public class Exmp3{
private Strig val;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
// GetAndSet
}
}
json获得的类:
@Service
public class InstrumentGetService {
RestTemplate restTemlate;
public List<Params> getInfo(String token,
String order) {
final var url = String.format(
"https://example.ru/rest/getOrderStatus.do?token=%s&orderId=%s", token, order);
GeneralExmp dto = restTemlate.getForObject(url, GeneralExmp.class);
return Collections.singletonList(toModel(dto));
}
告诉我如何正确实现toModel方法?我无法将get和set从Exmp类获取到Params构造函数中
@Service
public class InstrumentGetService {
RestTemplate restTemlate;
public List<Params> getInfo(String token,
String order) {
final var url = String.format(
"https://example.ru/rest/getOrderStatus.do?token=%s&orderId=%s", token, order);
GeneralExmp dto = restTemlate.getForObject(url, GeneralExmp.class);
return Collections.singletonList(toModel(dto));
}
public Params toModel(GeneralExmp dto) {
//??
return new Params(//? , //?);
}