Skip to content

Instantly share code, notes, and snippets.

@jnizet
Created August 11, 2019 14:36
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 jnizet/44c0bb9a1614952b7ac2beea480510fb to your computer and use it in GitHub Desktop.
Save jnizet/44c0bb9a1614952b7ac2beea480510fb to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collections;
import com.fasterxml.jackson.databind.ObjectMapper;
public class MyCustomObject{
private String appName;
public MyCustomObject(String appName){
this.appName = appName;
}
public String getAppName() {
return appName;
}
public static void main(String[] args) throws IOException {
MyCustomObject app = new MyCustomObject("{\"key\":\"value\"}");
ObjectMapper mapper = new ObjectMapper();
String myCustomObjectAsStr = mapper.writeValueAsString(app);
Files.write(Paths.get("test.json"), Collections.singletonList(myCustomObjectAsStr), Charset.forName("UTF-8"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment