Search in sources :

Example 11 with ForestFastjsonConverter

use of com.dtflys.forest.converter.json.ForestFastjsonConverter in project forest by dromara.

the class TestFastjsonConverter method testConfig.

@Test
public void testConfig() {
    ForestJsonConverter jsonConverter = forestConfiguration.getJsonConverter();
    assertThat(jsonConverter).isNotNull().isInstanceOf(ForestFastjsonConverter.class);
    ForestFastjsonConverter forestFastjsonConverter = (ForestFastjsonConverter) jsonConverter;
    assertThat(forestFastjsonConverter.getDateFormat()).isEqualTo("yyyy/MM/dd hh:mm:ss");
}
Also used : ForestFastjsonConverter(com.dtflys.forest.converter.json.ForestFastjsonConverter) ForestJsonConverter(com.dtflys.forest.converter.json.ForestJsonConverter) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 12 with ForestFastjsonConverter

use of com.dtflys.forest.converter.json.ForestFastjsonConverter in project forest by dromara.

the class TestForestConfiguration method testConverterMap.

@Test
public void testConverterMap() {
    ForestConfiguration configuration = ForestConfiguration.createConfiguration();
    assertNotNull(configuration.getConverterMap());
    Map<ForestDataType, ForestConverter> converterMap = new HashMap<>();
    converterMap.put(ForestDataType.JSON, new ForestFastjsonConverter());
    configuration.setConverterMap(converterMap);
    assertEquals(converterMap, configuration.getConverterMap());
}
Also used : ForestFastjsonConverter(com.dtflys.forest.converter.json.ForestFastjsonConverter) ForestConfiguration(com.dtflys.forest.config.ForestConfiguration) HashMap(java.util.HashMap) ForestConverter(com.dtflys.forest.converter.ForestConverter) ForestDataType(com.dtflys.forest.utils.ForestDataType) Test(org.junit.Test)

Example 13 with ForestFastjsonConverter

use of com.dtflys.forest.converter.json.ForestFastjsonConverter in project forest by dromara.

the class TestForestFastjsonConverter method testConvertToMap.

@Test
public void testConvertToMap() {
    TestObj testObj = new TestObj();
    testObj.setId(1);
    testObj.setBody("xxx");
    testObj.setCrc(new Byte("1"));
    testObj.setDirection(4);
    testObj.setType("yyy");
    ForestFastjsonConverter forestFastjsonConverter = new ForestFastjsonConverter();
    Map<String, Object> map = forestFastjsonConverter.convertObjectToMap(testObj);
    assertEquals("{\"id\":1,\"direction\":4,\"type\":\"yyy\",\"body\":\"xxx\",\"crc\":1}", JSON.toJSONString(map));
}
Also used : ForestFastjsonConverter(com.dtflys.forest.converter.json.ForestFastjsonConverter) Test(org.junit.Test)

Example 14 with ForestFastjsonConverter

use of com.dtflys.forest.converter.json.ForestFastjsonConverter in project forest by dromara.

the class TestForestFastjsonConverter method testConvertToJsonError.

@Test
public void testConvertToJsonError() {
    ForestFastjsonConverter forestFastjsonConverter = new ForestFastjsonConverter();
    Map map = new HashMap();
    map.put("ref", map);
    boolean error = false;
    try {
        forestFastjsonConverter.encodeToString(map);
    } catch (ForestRuntimeException e) {
        error = true;
        assertNotNull(e.getCause());
    }
    assertTrue(error);
}
Also used : ForestFastjsonConverter(com.dtflys.forest.converter.json.ForestFastjsonConverter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 15 with ForestFastjsonConverter

use of com.dtflys.forest.converter.json.ForestFastjsonConverter in project forest by dromara.

the class TestForestFastjsonConverter method testJavaObjectToMap.

@Test
public void testJavaObjectToMap() {
    Coordinate coordinate = new Coordinate("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"));
}
Also used : ForestFastjsonConverter(com.dtflys.forest.converter.json.ForestFastjsonConverter) SubCoordinate(com.dtflys.test.model.SubCoordinate) Coordinate(com.dtflys.test.model.Coordinate) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

ForestFastjsonConverter (com.dtflys.forest.converter.json.ForestFastjsonConverter)16 Test (org.junit.Test)16 HashMap (java.util.HashMap)9 LinkedHashMap (java.util.LinkedHashMap)9 Map (java.util.Map)8 ForestRuntimeException (com.dtflys.forest.exceptions.ForestRuntimeException)3 TypeReference (com.alibaba.fastjson.TypeReference)2 ForestConverter (com.dtflys.forest.converter.ForestConverter)2 SubCoordinate (com.dtflys.test.model.SubCoordinate)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 SerializerFeature (com.alibaba.fastjson.serializer.SerializerFeature)1 ForestConfiguration (com.dtflys.forest.config.ForestConfiguration)1 DefaultAutoConverter (com.dtflys.forest.converter.auto.DefaultAutoConverter)1 ForestJacksonConverter (com.dtflys.forest.converter.json.ForestJacksonConverter)1 ForestJsonConverter (com.dtflys.forest.converter.json.ForestJsonConverter)1 ForestConvertException (com.dtflys.forest.exceptions.ForestConvertException)1 ForestFileNotFoundException (com.dtflys.forest.exceptions.ForestFileNotFoundException)1 ForestHandlerException (com.dtflys.forest.exceptions.ForestHandlerException)1 ForestInterceptorDefineException (com.dtflys.forest.exceptions.ForestInterceptorDefineException)1 ForestNetworkException (com.dtflys.forest.exceptions.ForestNetworkException)1