diff --git a/src/main/java/com/foxsteps/gsonformat/ConvertBridge.java b/src/main/java/com/foxsteps/gsonformat/ConvertBridge.java index e7a42bd..e6b3b01 100644 --- a/src/main/java/com/foxsteps/gsonformat/ConvertBridge.java +++ b/src/main/java/com/foxsteps/gsonformat/ConvertBridge.java @@ -550,8 +550,9 @@ private List createFields(JSONObject json, Map fieldEntityList = new ArrayList(); List listEntityList = new ArrayList(); //是否添加注释 - boolean writeExtra = Config.getInstant().isGenerateComments(); - + //boolean writeExtra = Config.getInstant().isGenerateComments(); + //去掉构造函数注释 + boolean writeExtra=false; for (int i = 0; i < fieldList.size(); i++) { String key = fieldList.get(i); Object value = json.get(key); @@ -602,9 +603,19 @@ private FieldEntity createField(ClassEntity parentClass, String key, Object type } fieldName = StringUtils.captureStringLeaveUnderscore(fieldName.toLowerCase()); } else { + //fieldName是全部大写 if (Config.getInstant().isUseSerializedName() && StringUtils.isAcronym(fieldName)) { fieldName = fieldName.toLowerCase(); } + //首字母是大写,存在其他字母是小写 + if (StringUtils.isFirsrtUpper(fieldName)) { + if (fieldName.length() == 1) { + fieldName = fieldName.toLowerCase(); + }else{ + fieldName = fieldName.substring(0,1).toLowerCase()+ fieldName.substring(1); + } + } + } fieldName = handleDeclareFieldName(fieldName, ""); diff --git a/src/main/java/com/foxsteps/gsonformat/common/StringUtils.java b/src/main/java/com/foxsteps/gsonformat/common/StringUtils.java index 4e7f4af..9e98bc3 100644 --- a/src/main/java/com/foxsteps/gsonformat/common/StringUtils.java +++ b/src/main/java/com/foxsteps/gsonformat/common/StringUtils.java @@ -41,6 +41,14 @@ public static boolean isAcronym(String word) { return true; } + public static boolean isFirsrtUpper(String word) { + char c = word.charAt(0); + if(Character.isUpperCase(c)){ + return true; + } + return false; + } + public static String captureName(String text) { diff --git a/src/main/java/com/foxsteps/gsonformat/config/Config.java b/src/main/java/com/foxsteps/gsonformat/config/Config.java index d81be37..b1b47af 100644 --- a/src/main/java/com/foxsteps/gsonformat/config/Config.java +++ b/src/main/java/com/foxsteps/gsonformat/config/Config.java @@ -122,7 +122,7 @@ public static Config getInstant() { config.setErrorCount(PropertiesComponent.getInstance().getOrInitInt("errorCount", 0)); config.setVirgoMode(PropertiesComponent.getInstance().getBoolean("virgoMode", true)); config.setUseFieldNamePrefix(PropertiesComponent.getInstance().getBoolean("useFieldNamePrefix", false)); - config.setGenerateComments(PropertiesComponent.getInstance().getBoolean("generateComments", true)); + config.setGenerateComments(PropertiesComponent.getInstance().getBoolean("generateComments", false)); config.setSplitGenerate(PropertiesComponent.getInstance().getBoolean("splitGenerate", false)); config.setUseWrapperClass(PropertiesComponent.getInstance().getBoolean("useWrapperClass", true)); config.setUseComment(PropertiesComponent.getInstance().getBoolean("useComment", false)); diff --git a/src/main/java/com/foxsteps/gsonformat/ui/JsonDialog.java b/src/main/java/com/foxsteps/gsonformat/ui/JsonDialog.java index de18262..ee67ce6 100644 --- a/src/main/java/com/foxsteps/gsonformat/ui/JsonDialog.java +++ b/src/main/java/com/foxsteps/gsonformat/ui/JsonDialog.java @@ -208,8 +208,34 @@ public void actionPerformed(ActionEvent e) { if (!StringUtils.isNotBlank(json)) { return; } - SystemUtils.copyToClipboard(json); - NotificationCenter.sendNotificationForProject(" Copy json success !",NotificationType.INFORMATION,project); + String formatJson=""; + try { + if (json.startsWith("{")) { + JSONObject jsonObject = new JSONObject(json); + formatJson = jsonObject.toString(4); + editTP.setText(formatJson); + } else if (json.startsWith("[")) { + JSONArray jsonArray = new JSONArray(json); + formatJson = jsonArray.toString(4); + editTP.setText(formatJson); + } + SystemUtils.copyToClipboard(formatJson); + NotificationCenter.sendNotificationForProject(" Copy json success !",NotificationType.INFORMATION,project); + } catch (JSONException jsonException) { + try { + String goodJson = JsonUtils.removeComment(json); + formatJson = JsonUtils.formatJson(goodJson); + editTP.setText(formatJson); + commentAR.setText(JsonUtils.getJsonComment(json, formatJson)); + SystemUtils.copyToClipboard(formatJson); + NotificationCenter.sendNotificationForProject(" Copy json success !",NotificationType.INFORMATION,project); + } catch (Exception exception) { + formatJson=""; + exception.printStackTrace(); + NotificationCenter.sendNotificationForProject("json格式不正确,格式需要标准的json或者json5",NotificationType.ERROR,project); + return; + } + } } }); diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 81ea660..6c94996 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,6 +1,6 @@ GsonFormatPlus - 1.5.8 + 1.5.9