use of com.dtflys.forest.converter.json.ForestJacksonConverter in project forest by dromara.
the class TestForestJacksonConverter method testMapToJSONString.
@Test
public void testMapToJSONString() throws ParseException {
Map<String, Object> map = new LinkedHashMap<>();
map.put("name", "foo");
map.put("password", "bar");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date date = dateFormat.parse("2020-10-10 10:10:10");
map.put("createDate", date);
ForestJacksonConverter forestJacksonConverter = new ForestJacksonConverter();
forestJacksonConverter.setDateFormat("yyyy/MM/dd hh:mm:ss");
String jsonStr = forestJacksonConverter.encodeToString(map);
assertEquals("{\"name\":\"foo\",\"password\":\"bar\",\"createDate\":\"2020/10/10 10:10:10\"}", jsonStr);
}
use of com.dtflys.forest.converter.json.ForestJacksonConverter in project forest by dromara.
the class TestForestJacksonConverter method testJavaObjectToMap2.
@Test
public void testJavaObjectToMap2() {
SubCoordinate coordinate = new SubCoordinate("11.11111", "22.22222");
ForestJacksonConverter forestJacksonConverter = new ForestJacksonConverter();
Map map = forestJacksonConverter.convertObjectToMap(coordinate);
assertNotNull(map);
assertEquals("11.11111", map.get("longitude"));
assertEquals("22.22222", map.get("latitude"));
}
Aggregations