예제 #1
0
  public void test_1() throws Exception {
    SerializeConfig config = new SerializeConfig();
    config.setAsmEnable(true);

    String text = JSON.toJSONString(new Entity(), config);
    Assert.assertEquals("{\"value\":0}", text);
  }
예제 #2
0
  public void test_codec_asm() throws Exception {
    V0 v = new V0();
    v.setValue(new Date());

    SerializeConfig mapping = new SerializeConfig();
    mapping.setAsmEnable(true);

    String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", JSON.defaultLocale);
    format.setTimeZone(JSON.defaultTimeZone);
    Assert.assertEquals("{\"value\":" + JSON.toJSONString(format.format(v.getValue())) + "}", text);
  }
예제 #3
0
  public void test_codec_null() throws Exception {
    V0 v = new V0();

    SerializeConfig mapping = new SerializeConfig();
    mapping.setAsmEnable(false);

    String text = JSON.toJSONString(v, mapping, SerializerFeature.WriteMapNullValue);
    Assert.assertEquals("{\"value\":null}", text);

    V0 v1 = JSON.parseObject(text, V0.class);

    Assert.assertEquals(v1.getValue(), v.getValue());
  }
예제 #4
0
  public void test_codec_null_1() throws Exception {
    V0 v = new V0();

    SerializeConfig mapping = new SerializeConfig();
    mapping.setAsmEnable(false);

    Assert.assertEquals(
        "{\"value\":null}",
        JSON.toJSONString(
            v,
            mapping,
            SerializerFeature.WriteMapNullValue,
            SerializerFeature.WriteNullListAsEmpty));
    Assert.assertEquals(
        "{value:null}",
        JSON.toJSONStringZ(
            v,
            mapping,
            SerializerFeature.WriteMapNullValue,
            SerializerFeature.WriteNullListAsEmpty));
    Assert.assertEquals(
        "{value:null}",
        JSON.toJSONStringZ(
            v,
            mapping,
            SerializerFeature.UseSingleQuotes,
            SerializerFeature.WriteMapNullValue,
            SerializerFeature.WriteNullListAsEmpty));
    Assert.assertEquals(
        "{'value':null}",
        JSON.toJSONStringZ(
            v,
            mapping,
            SerializerFeature.UseSingleQuotes,
            SerializerFeature.QuoteFieldNames,
            SerializerFeature.WriteMapNullValue,
            SerializerFeature.WriteNullListAsEmpty));
  }