Created
October 23, 2019 10:07
-
-
Save moriya-hm5/b9db242d661c2dbb87238e081a7fb8d5 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 com.fasterxml.jackson.core.JsonProcessingException; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import lombok.Getter; | |
import lombok.Setter; | |
public class SampleJackson1 { | |
private static ObjectMapper mapper = new ObjectMapper(); | |
@Getter | |
@Setter | |
private String id; | |
@Getter | |
@Setter | |
private String name; | |
// コンストラクタ | |
SampleJackson1() { | |
mapper.enable(SerializationFeature.INDENT_OUTPUT); // これで整形される | |
} | |
public static void main(String[] args) throws JsonProcessingException { | |
SampleJackson1 jackson = new SampleJackson1(); | |
jackson.setId("1"); | |
jackson.setName("takahashi"); | |
String json = mapper.writeValueAsString(jackson); | |
System.out.println(json); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment