Esempio n. 1
0
  private static void setFilter(JSONSerializer serializer, SerializeFilter filter) {
    if (filter == null) {
      return;
    }

    if (filter instanceof PropertyPreFilter) {
      serializer.getPropertyPreFilters().add((PropertyPreFilter) filter);
    }

    if (filter instanceof NameFilter) {
      serializer.getNameFilters().add((NameFilter) filter);
    }

    if (filter instanceof ValueFilter) {
      serializer.getValueFilters().add((ValueFilter) filter);
    }

    if (filter instanceof PropertyFilter) {
      serializer.getPropertyFilters().add((PropertyFilter) filter);
    }

    if (filter instanceof BeforeFilter) {
      serializer.getBeforeFilters().add((BeforeFilter) filter);
    }

    if (filter instanceof AfterFilter) {
      serializer.getAfterFilters().add((AfterFilter) filter);
    }

    if (filter instanceof LabelFilter) {
      serializer.getLabelFilters().add((LabelFilter) filter);
    }
  }
Esempio n. 2
0
  public void test_namefilter() throws Exception {
    NameFilter filter =
        new NameFilter() {

          public String process(Object source, String name, Object value) {
            if (name.equals("id")) {
              return "ID";
            }

            return name;
          }
        };

    SerializeWriter out = new SerializeWriter();
    JSONSerializer serializer = new JSONSerializer(out);
    serializer.getNameFilters().add(filter);

    Bean a = new Bean();
    serializer.write(a);

    String text = out.toString();
    Assert.assertEquals("{\"ID\":0}", text);
  }