Home > Back-end >  Jackson's tools
Jackson's tools

Time:11-23

 
Package com. Example. Fuxi. Utils;

The import com. Fasterxml. Jackson. Core. JsonProcessingException;
The import com. Fasterxml. Jackson. Databind. ObjectMapper;
The import com. Fasterxml. Jackson. Databind. SerializationFeature;
Import the Java. Text. SimpleDateFormat;
Public class jsonUntil {

Public static String getJson (Object obj) {
Return the getJson (obj, "YYYY - MM - DD HH: MM: SS");
}

Public static String getJson (Object obj, String DateFormat) {
ObjectMapper mapper=new ObjectMapper ();
Mapper. The configure (SerializationFeature WRITE_DATES_AS_TIMESTAMPS, false);
Final SimpleDateFormat SDF=new SimpleDateFormat (DateFormat);
Mapper. SetDateFormat (SDF);
Try {
Return mapper. WriteValueAsString (obj);
} the catch (JsonProcessingException e) {
e.printStackTrace();
}
return null;
}

}


Whether very concise

CodePudding user response:


Com. Alibaba
Fastjson
1.1.41 & lt;/version>

With this package the JSONObject inside a see method with JSONArray class know is stem what of
  • Related