use of com.dtflys.forest.converter.json.ForestJacksonConverter in project forest by dromara.
the class TestJacksonConverter method testConfig.
@Test
public void testConfig() {
ForestJsonConverter jsonConverter = forestConfiguration.getJsonConverter();
assertThat(jsonConverter).isNotNull().isInstanceOf(ForestJacksonConverter.class);
ForestJacksonConverter forestJacksonConverter = (ForestJacksonConverter) jsonConverter;
assertThat(forestJacksonConverter.getDateFormat()).isEqualTo("yyyy/MM/dd hh:mm:ss");
}
use of com.dtflys.forest.converter.json.ForestJacksonConverter in project forest by dromara.
the class TestForestConfiguration method testJSONConverterSelect.
@Test
public void testJSONConverterSelect() throws Throwable {
JSONConverterSelector jsonConverterSelector = new JSONConverterSelector();
JSONConverterSelector spy = Mockito.spy(jsonConverterSelector);
Mockito.when(spy.checkFastJSONClass()).thenThrow(new ClassNotFoundException("com.alibaba.fastjson.JSON"));
ForestJsonConverter jsonConverter = spy.select();
assertNotNull(jsonConverter);
assertTrue(jsonConverter instanceof ForestJacksonConverter);
jsonConverterSelector = new JSONConverterSelector();
spy = Mockito.spy(jsonConverterSelector);
Mockito.when(spy.checkFastJSONClass()).thenThrow(new ClassNotFoundException("com.alibaba.fastjson.JSON"));
Mockito.when(spy.checkJacsonClass()).thenThrow(new ClassNotFoundException("com.fasterxml.jackson.databind.ObjectMapper"));
jsonConverter = spy.select();
assertNotNull(jsonConverter);
assertTrue(jsonConverter instanceof ForestGsonConverter);
jsonConverterSelector = new JSONConverterSelector();
spy = Mockito.spy(jsonConverterSelector);
Mockito.when(spy.checkFastJSONClass()).thenThrow(new ClassNotFoundException("com.alibaba.fastjson.JSON"));
Mockito.when(spy.checkJacsonClass()).thenThrow(new ClassNotFoundException("com.fasterxml.jackson.databind.ObjectMapper"));
Mockito.when(spy.checkGsonClass()).thenThrow(new ClassNotFoundException("com.google.gson.JsonParser"));
jsonConverter = spy.select();
assertNull(jsonConverter);
}
use of com.dtflys.forest.converter.json.ForestJacksonConverter in project forest by dromara.
the class TestAmapClient method prepareClient.
// @BeforeClass
public static void prepareClient() {
configuration = Forest.config();
configuration.setJsonConverter(new ForestJacksonConverter());
configuration.setCacheEnabled(false);
amapClient = configuration.createInstance(AmapClient.class);
}
use of com.dtflys.forest.converter.json.ForestJacksonConverter in project forest by dromara.
the class TestForestJacksonConverter method testConvertToJsonError.
@Test
public void testConvertToJsonError() {
ForestJacksonConverter forestJacksonConverter = new ForestJacksonConverter();
Map map = new HashMap();
map.put("ref", map);
boolean error = false;
try {
forestJacksonConverter.encodeToString(map);
} catch (ForestRuntimeException e) {
error = true;
assertNotNull(e.getCause());
}
assertTrue(error);
}
use of com.dtflys.forest.converter.json.ForestJacksonConverter in project forest by dromara.
the class TestForestJacksonConverter method testDate.
@Test
public void testDate() throws ParseException {
ForestJacksonConverter forestJacksonConverter = new ForestJacksonConverter();
String json = "{\"name\":\"foo\",\"date\":\"2020-10-10 10:12:00\"}";
forestJacksonConverter.setDateFormat("yyyy-MM-dd hh:mm:ss");
TestJsonObj testJsonObj = forestJacksonConverter.convertToJavaObject(json, TestJsonObj.class);
assertNotNull(testJsonObj);
assertEquals("foo", testJsonObj.getName());
assertDateEquals("2020-10-10 10:12:00", testJsonObj.getDate(), "yyyy-MM-dd hh:mm:ss");
json = "{\"name\":\"foo\",\"date\":\"2020/10/10 10:12:00\"}";
forestJacksonConverter.setDateFormat("yyyy/MM/dd hh:mm:ss");
testJsonObj = forestJacksonConverter.convertToJavaObject(json, TestJsonObj.class);
assertNotNull(testJsonObj);
assertEquals("foo", testJsonObj.getName());
assertDateEquals("2020-10-10 10:12:00", testJsonObj.getDate(), "yyyy-MM-dd hh:mm:ss");
}
Aggregations