小编Sri*_*vas的帖子

使用Jackson将JSON字符串数组映射到List <String>

我有从服务器返回的以下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>离开.

json jackson

8
推荐指数
3
解决办法
2万
查看次数

mapstruct List&lt;Object1&gt; 到 List&lt;Object2&gt; 具有不同的属性

我必须使用不同的属性名称将 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 是未知属性。有没有办法做到这一点?帮助表示赞赏。

mapstruct

1
推荐指数
1
解决办法
4463
查看次数

Kotlin Data class

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 …

kotlin

0
推荐指数
1
解决办法
108
查看次数

标签 统计

jackson ×1

json ×1

kotlin ×1

mapstruct ×1