Last active
October 23, 2019 22:20
-
-
Save moriya-hm5/ef779db32f1123c1ee8479a9dd8a91a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.co.jackson; | |
import java.util.LinkedHashMap; | |
import java.util.List; | |
import java.util.Map; | |
import com.fasterxml.jackson.core.JsonProcessingException; | |
import com.fasterxml.jackson.core.type.TypeReference; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import lombok.Getter; | |
import lombok.Setter; | |
import lombok.ToString; | |
public class SampleJackson1 { | |
private static ObjectMapper mapper = new ObjectMapper(); | |
public static void main(String[] args) throws JsonProcessingException { | |
String json = "[{\"id\":20,\"name\":\"takahashi\"},{\"id\":20,\"name\":\"higashiguchi\"}]"; | |
List<Emp> person1 = mapper.readValue(json,new TypeReference<List<Emp>>() {}); | |
System.out.println(person1); | |
json = "{\"id\":20,\"name\":\"takahashi\"},{\"id\":20,\"name\":\"higashiguchi\"}"; | |
Map<String,String> person2 = mapper.readValue(json,new TypeReference<LinkedHashMap<String,String>>() {}); | |
System.out.println(person2); | |
} | |
} | |
@Getter | |
@Setter | |
@ToString | |
class Emp { | |
private String id; | |
private String name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment