APISonar


org.osgl.http.H.Format.JSON

> org > osgl > http > H > Format > JSON
org APIs osgl APIs http APIs H APIs Format APIs JSON APIs

Example 1
public void mockFormat(String fmt) {
        if ("json".equals(fmt)) {
            context.accept(H.Format.JSON);
        }
        context.session().put("foo", "bar");
    }
Example 2
public void testPost() throws Exception {
        url("/gh/353").accept(H.Format.JSON).postJSON(user);
        String s = resp().body().string();
        User user2 = JSON.parseObject(s, User.class);
        eq(user.name, user2.name);
    }
Example 3
public void postFullContactJsonBody() throws Exception {
        Contact contact = prepareFullContact();
        context.expected(JSON.toJSONString(contact))
                .url(processUrl("ctct"))
                .accept(H.Format.JSON)
                .jsonBody(C.Map("contact", contact))
                .method(EndPointTestContext.RequestMethod.POST_JSON)
                .applyTo(this);
    }
Example 4
public void apply(ActionContext context) {
        context.accept(H.Format.JSON);
        super.apply(context);
    }
Example 5
public void testFastJsonFilter() throws Exception {
        url("/gh/426").get("name", "Tom", "count", 3).accept(H.Format.JSON);
        JSONObject obj = JSON.parseObject(resp().body().string());
        eq("Tom", obj.getString("Name"));
        eq(3, obj.getInteger("BarCount"));
        // TODO uncomment the following line once
        // we get https://github.com/alibaba/fastjson/issues/1635 fixed
        // in FastJSON
        //no(obj.getBoolean("Flag"));
    }
Example 6
private void fixRequestAcceptFormat(ActionContext context) {
        H.Request req = context.req();
        if (null != req && !isAcceptGoodForErrorPage(req.accept())) {
            req.accept(H.Format.JSON);
        }
    }
Example 7
public void test() throws Exception {
        String prodId = "Car 007";
        GH317.Product product = new GH317.Product(prodId);
        int quantity = 3;
        Map<String, Object> order = C.Map("prod", prodId, "quantity", 3);
        url("/gh/317").postJSON(order).accept(H.Format.JSON);
        String s = resp().body().string();
        System.out.println(s);
        checkRespCode();
    }
Example 8
public void normalCaseWithPojoBind() throws IOException {
        Address address = new Address(Country.ZH, SiChuan);
        url("/bind/custom/pojo")
                .post("address.country", address.country, "address.state", address.state)
                .accept(H.Format.JSON);
        String s = resp().body().string();
        eq(JSON.toJSONString(address), s);
    }
Example 9
public void apply(ActionContext context) {
        context.accept(H.Format.JSON);
        JsonWebTokenSessionCodec codec = Act.getInstance(JsonWebTokenSessionCodec.class);
        String token = codec.encodeSession(context.session());
        //H.Request req = context.req();
        H.Response resp = context.resp();
        //applyBeforeCommitHandler(req, resp);
        resp.writeContent(S.concat("{\"token\":\"", token, "\"}"));
        //applyAfterCommitHandler(req, resp);
    }