Created
August 11, 2019 14:36
-
-
Save jnizet/44c0bb9a1614952b7ac2beea480510fb 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
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