use of com.dtflys.forest.converter.json.ForestFastjsonConverter in project forest by dromara.
the class TestForestFastjsonConverter method testDate.
@Test
public void testDate() throws ParseException {
String json = "{\"name\":\"foo\",\"date\":\"2020-10-10 10:12:00\"}";
ForestFastjsonConverter forestFastjsonConverter = new ForestFastjsonConverter();
TestJsonObj testJsonObj = forestFastjsonConverter.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\"}";
testJsonObj = forestFastjsonConverter.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");
}
use of com.dtflys.forest.converter.json.ForestFastjsonConverter in project forest by dromara.
the class TestForestFastjsonConverter method testJavaObjectToMap2.
@Test
public void testJavaObjectToMap2() {
SubCoordinate coordinate = new SubCoordinate("11.11111", "22.22222");
ForestFastjsonConverter forestFastjsonConverter = new ForestFastjsonConverter();
Map map = forestFastjsonConverter.convertObjectToMap(coordinate);
assertNotNull(map);
assertEquals("11.11111", map.get("longitude"));
assertEquals("22.22222", map.get("latitude"));
}
use of com.dtflys.forest.converter.json.ForestFastjsonConverter in project forest by dromara.
the class TestForestFastjsonConverter method testConvertToJavaError.
@Test
public void testConvertToJavaError() {
String badJsonText = "{\"a\":1";
ForestFastjsonConverter forestFastjsonConverter = new ForestFastjsonConverter();
boolean error = false;
try {
forestFastjsonConverter.convertToJavaObject(badJsonText, Map.class);
} catch (ForestRuntimeException e) {
error = true;
assertNotNull(e.getCause());
}
assertTrue(error);
error = true;
try {
forestFastjsonConverter.convertToJavaObject(badJsonText, new TypeReference<Map>() {
}.getType());
} catch (ForestRuntimeException e) {
error = true;
assertNotNull(e.getCause());
}
assertTrue(error);
error = true;
try {
forestFastjsonConverter.convertToJavaObject(badJsonText, new TypeReference<Map>() {
});
} catch (ForestRuntimeException e) {
error = true;
assertNotNull(e.getCause());
}
assertTrue(error);
}
use of com.dtflys.forest.converter.json.ForestFastjsonConverter in project forest by dromara.
the class TestExceptions method testConvertException.
@Test
public void testConvertException() {
Throwable th = new Exception("xxx");
ForestConverter<?> converter = new ForestFastjsonConverter();
ForestConvertException exception = new ForestConvertException(converter, th);
assertThat(exception.getMessage()).isEqualTo("[Forest] json converter: 'ForestFastjsonConverter' error: xxx");
assertThat(exception.getConverterClass()).isEqualTo(ForestFastjsonConverter.class);
converter = new ForestJacksonConverter();
exception = new ForestConvertException(converter, th);
assertThat(exception.getMessage()).isEqualTo("[Forest] json converter: 'ForestJacksonConverter' error: xxx");
assertThat(exception.getConverterClass()).isEqualTo(ForestJacksonConverter.class);
converter = new DefaultAutoConverter(ForestConfiguration.configuration());
exception = new ForestConvertException(converter, th);
assertThat(exception.getMessage()).isEqualTo("[Forest] auto converter: 'DefaultAutoConverter' error: xxx");
assertThat(exception.getConverterClass()).isEqualTo(DefaultAutoConverter.class);
}
use of com.dtflys.forest.converter.json.ForestFastjsonConverter in project forest by dromara.
the class TestConverterBeanListener method test1.
@Test
public void test1() {
ForestConverter forestConverter = forestConfiguration.getConverterMap().get(ForestDataType.JSON);
assertTrue(forestConverter instanceof ForestFastjsonConverter);
ForestRequest<String> request = giteeClient.index2();
System.out.println(request.execute());
}
Aggregations