Skip to content

Instantly share code, notes, and snippets.

@moriya-hm5
Created October 23, 2019 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moriya-hm5/b9db242d661c2dbb87238e081a7fb8d5 to your computer and use it in GitHub Desktop.
Save moriya-hm5/b9db242d661c2dbb87238e081a7fb8d5 to your computer and use it in GitHub Desktop.
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