我有从服务器返回的以下JSON.
String json = {
"values": ["name","city","dob","zip"]
};
Run Code Online (Sandbox Code Playgroud)
我想用来ObjectMapper返回List<String>值.就像是:
List<String> response = mapper.readValue(json, List.class)
Run Code Online (Sandbox Code Playgroud)
我尝试了几种方法,但没有一种方法可行.任何帮助表示赞赏.
编辑:我不想要额外的包装器对象.我想马上List<String>离开.
我必须使用不同的属性名称将 List 映射到 List。
前任:
public class Object1 {
private String name;
//getters and setters
}
public class Object2 {
private String customerName;
//getters and setters
}
@Mapping(source="object1List.name" target="object2List.customerName"
List<Object2> toObject2(final List<Object1> object1List)
Run Code Online (Sandbox Code Playgroud)
我没有写我在哪里得到 Object1List 来简化。(我在一个方法的不同类中得到了它)
我一直在尝试这个,但 mapstruct 抱怨 object1List 是未知属性。有没有办法做到这一点?帮助表示赞赏。
I have below POJO in java which is used in Spring boot app to inject properties from YML during the app startup. Trying to convert the app into Kotlin but I have struggle implementing the values injected when I converted the POJO to data class.
@Component
@ConfigurationProperties("rest")
@Data
public class RestProperties {
private final Client client = new Client();
@Data
public static class Client {
private int defaultMaxTotalConnections;
private int defaultMaxConnectionsPerRoute;
private int defaultReadTimeout;
}
}
Run Code Online (Sandbox Code Playgroud)
I have tried below …