我的回答就像
"preferentialManufacturingRegionCode":
“布列斯特”、“维捷布斯克”、“戈梅尔”、“明斯克”
How to convert List of strings to objects that in respone will be like
"preferentialManufacturingRegionCode": [
{
"value": "Brest",
},
{
"value": "Vitebsk",
},
{
"value": "Gomel",
},
{
"value": "Minsk",
},
]
I will be grateful for your answer发布于 2022-11-11 08:13:56
定义类Value
public class Value<T> {
private final T value;
public Value(T value) {
this.value = value;
}
public T getValue() {
return value;
}
}您现在可以按以下方式转换您的List<String>:
List<Value<String>> values = list.stream()
.map(Value::new)
.collect(Collectors.toList());更新:
使用JSON生成器生成JSON。例如,对于Jackson:
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(System.out, values);输出:
[{"value":"Brest"},{"value":"Vitebsk"},{"value":"Gomel"},{"value":"Minsk"}]https://stackoverflow.com/questions/74399453
复制相似问题