Search in sources :

Example 1 with FastJsonJsonView

use of com.alibaba.fastjson.support.spring.FastJsonJsonView in project fastjson by alibaba.

the class FastJsonJsonViewTest method test_0.

@SuppressWarnings("deprecation")
public void test_0() throws Exception {
    FastJsonJsonView view = new FastJsonJsonView();
    Assert.assertEquals(Charset.forName("UTF-8"), view.getCharset());
    view.setCharset(Charset.forName("GBK"));
    Assert.assertEquals(Charset.forName("GBK"), view.getCharset());
    Assert.assertNull(view.getDateFormat());
    view.setDateFormat("yyyyMMdd");
    Assert.assertNotNull(view.getFeatures());
    Assert.assertEquals(0, view.getFeatures().length);
    view.setSerializerFeature(SerializerFeature.BrowserCompatible);
    Assert.assertEquals(1, view.getFeatures().length);
    Assert.assertEquals(SerializerFeature.BrowserCompatible, view.getFeatures()[0]);
    view.setFeatures(SerializerFeature.DisableCheckSpecialChar, SerializerFeature.SortField);
    Assert.assertEquals(2, view.getFeatures().length);
    Assert.assertEquals(SerializerFeature.DisableCheckSpecialChar, view.getFeatures()[0]);
    Assert.assertEquals(SerializerFeature.SortField, view.getFeatures()[1]);
    view.setFilters(serializeFilter);
    Assert.assertEquals(1, view.getFilters().length);
    Assert.assertEquals(serializeFilter, view.getFilters()[0]);
    Map<String, Object> model = new HashMap<String, Object>();
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    view.render(model, request, response);
    view.setRenderedAttributes(null);
    view.setCharset(Charset.forName("UTF-8"));
    view.render(model, request, response);
    view.setUpdateContentLength(true);
    view.setFeatures(SerializerFeature.BrowserCompatible);
    view.render(model, request, response);
    view.setCharset(Charset.forName("GBK"));
    view.render(Collections.singletonMap("abc", "cde"), request, response);
    view.setDisableCaching(false);
    view.setUpdateContentLength(false);
    view.render(model, request, response);
    view.setRenderedAttributes(new HashSet<String>(Collections.singletonList("abc")));
    view.render(Collections.singletonMap("abc", "cde"), request, response);
}
Also used : FastJsonJsonView(com.alibaba.fastjson.support.spring.FastJsonJsonView) HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 2 with FastJsonJsonView

use of com.alibaba.fastjson.support.spring.FastJsonJsonView in project fastjson by alibaba.

the class FastJsonJsonViewTest method test_1.

public void test_1() throws Exception {
    FastJsonJsonView view = new FastJsonJsonView();
    Assert.assertNotNull(view.getFastJsonConfig());
    view.setFastJsonConfig(new FastJsonConfig());
    Map<String, Object> model = new HashMap<String, Object>();
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    view.render(model, request, response);
    view.setRenderedAttributes(null);
    view.render(model, request, response);
    view.setUpdateContentLength(true);
    view.render(model, request, response);
    view.setExtractValueFromSingleKeyModel(true);
    Assert.assertEquals(true, view.isExtractValueFromSingleKeyModel());
    view.setDisableCaching(true);
    view.render(Collections.singletonMap("abc", "cde"), request, response);
}
Also used : FastJsonJsonView(com.alibaba.fastjson.support.spring.FastJsonJsonView) FastJsonConfig(com.alibaba.fastjson.support.config.FastJsonConfig) HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Aggregations

FastJsonJsonView (com.alibaba.fastjson.support.spring.FastJsonJsonView)2 HashMap (java.util.HashMap)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 FastJsonConfig (com.alibaba.fastjson.support.config.FastJsonConfig)1