11package com .xwintop .xcore .util .javafx ;
22
3+ import com .alibaba .fastjson2 .JSON ;
4+ import com .alibaba .fastjson2 .JSONWriter ;
35import javafx .collections .FXCollections ;
46import javafx .collections .ObservableList ;
57import javafx .scene .control .*;
911import lombok .extern .slf4j .Slf4j ;
1012import org .apache .commons .io .FileUtils ;
1113import org .apache .commons .lang3 .StringUtils ;
12- import org .yaml .snakeyaml .Yaml ;
1314
1415import java .io .File ;
1516import java .util .HashMap ;
3132@ Slf4j
3233public class TextFieldInputHistoryDialog {
3334 private ObservableList <Map <String , String >> tableData = FXCollections .observableArrayList ();
35+
3436 private String saveFilePath = null ;
37+
3538 private String [] tableColumns = null ;
39+
3640 private ContextMenu contextMenu = new ContextMenu ();
3741
3842 public TextFieldInputHistoryDialog (String saveFilePath , String ... tableColumns ) {
@@ -70,8 +74,7 @@ public void loadingConfigure() {
7074 if (!CONFIG_FILE .exists ()) {
7175 FileUtils .touch (CONFIG_FILE );
7276 }
73- Yaml yaml = new Yaml ();
74- List <Map <String , String >> list = yaml .load (FileUtils .readFileToString (CONFIG_FILE , "UTF-8" ));
77+ List <Map <String , String >> list = JSON .parseObject (FileUtils .readFileToString (CONFIG_FILE , "UTF-8" ), List .class );
7578 if (list != null ) {
7679 this .tableData .addAll (list );
7780 }
@@ -85,8 +88,7 @@ public void saveConfigure() {
8588 if (StringUtils .isNotEmpty (saveFilePath )) {
8689 try {
8790 File CONFIG_FILE = new File (saveFilePath );
88- Yaml yaml = new Yaml ();
89- FileUtils .writeStringToFile (CONFIG_FILE , yaml .dump (this .tableData ), "UTF-8" );
91+ FileUtils .writeStringToFile (CONFIG_FILE , JSON .toJSONString (this .tableData , JSONWriter .Feature .PrettyFormat , JSONWriter .Feature .WriteMapNullValue ), "UTF-8" );
9092 TooltipUtil .showToast ("保存配置成功,保存在:" + CONFIG_FILE .getPath ());
9193 } catch (Exception e ) {
9294 log .error ("保存配置失败" , e );
0 commit comments