试图了解一些杰克逊,所以我正在编写一个简单的程序来读取文件/创建一个文件来存储一些JSON.在Jackson网站上,我想出了如何从文件中读取和写入,但在我的基本程序中,我也想附加.我基本上试图存储一个购物清单列表.有一个购物清单对象,其中包含商店名称,该商店的amd商品.
麻烦的是我无法找到将另一个条目追加到文件末尾的方法(采用JSON格式).这是我到目前为止所使用的,您可以忽略它的第一位,它只是一个愚蠢的控制台扫描仪要求输入:
public class JacksonExample {
static ObjectMapper mapper = new ObjectMapper();
static File file = new File("C:/Users/stephen.protzman/Desktop/user.json");
static List master = new ArrayList();
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
boolean running = true;
while (running) {
System.out.println("[ 1 ] Add a new shopping list");
System.out.println("[ 2 ] View all shopping lists");
System.out.println("[ 3 ] Save all shopping lists");
int choice = Integer.parseInt(in.nextLine());
switch (choice) {