Ejemplo n.º 1
0
  public static final String toJSONStringZ(
      Object object, SerializeConfig mapping, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter(features);

    try {
      JSONSerializer serializer = new JSONSerializer(out, mapping);

      serializer.write(object);

      return out.toString();
    } finally {
      out.close();
    }
  }
Ejemplo n.º 2
0
  public static final void writeJSONStringTo(
      Object object, Writer writer, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter(writer);

    try {
      JSONSerializer serializer = new JSONSerializer(out);
      for (org.kf5.support.fastjson.serializer.SerializerFeature feature : features) {
        serializer.config(feature, true);
      }

      serializer.write(object);
    } finally {
      out.close();
    }
  }
Ejemplo n.º 3
0
  public static final byte[] toJSONBytes(Object object, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter();

    try {
      JSONSerializer serializer = new JSONSerializer(out);
      for (org.kf5.support.fastjson.serializer.SerializerFeature feature : features) {
        serializer.config(feature, true);
      }

      serializer.write(object);

      return out.toBytes("UTF-8");
    } finally {
      out.close();
    }
  }
Ejemplo n.º 4
0
  public static final String toJSONString(
      Object object, SerializeFilter[] filters, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter();

    try {
      JSONSerializer serializer = new JSONSerializer(out);
      for (org.kf5.support.fastjson.serializer.SerializerFeature feature : features) {
        serializer.config(feature, true);
      }

      serializer.config(SerializerFeature.WriteDateUseDateFormat, true);

      setFilter(serializer, filters);

      serializer.write(object);

      return out.toString();
    } finally {
      out.close();
    }
  }
Ejemplo n.º 5
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);
    }
  }
Ejemplo n.º 6
0
  /** @since 1.1.14 */
  public static final String toJSONStringWithDateFormat(
      Object object, String dateFormat, SerializerFeature... features) {
    SerializeWriter out = new SerializeWriter();

    try {
      JSONSerializer serializer = new JSONSerializer(out);
      for (SerializerFeature feature : features) {
        serializer.config(feature, true);
      }

      serializer.config(SerializerFeature.WriteDateUseDateFormat, true);

      if (dateFormat != null) {
        serializer.setDateFormat(dateFormat);
      }

      serializer.write(object);

      return out.toString();
    } finally {
      out.close();
    }
  }