Package net.sf.json.processors

Examples of net.sf.json.processors.JsonValueProcessor


  }

  public static JsonConfig filterDateConfig() {
    JsonConfig cfg = new JsonConfig();
    cfg.registerJsonValueProcessor(java.util.Date.class,
        new JsonValueProcessor() {
          private final String format = "yyyy-MM-dd HH:mm:ss";

          public Object processObjectValue(String key, Object value,
              JsonConfig arg2) {
            if (value == null)
View Full Code Here


    return config;
  }

  private static JsonConfig filterConfig() {
    JsonConfig config = new JsonConfig();
    JsonValueProcessor jp = new DateJsonValueProcessor(
        "yyyy-MM-dd HH:mm:ss");
    config.registerJsonValueProcessor(java.sql.Timestamp.class, jp);
    return config;
  }
View Full Code Here

  public JsonUtils()
  {
    jsonConfig = new JsonConfig();

    jsonConfig.registerJsonValueProcessor(DateTime.class,
        new JsonValueProcessor() {
          public Object processArrayValue(Object arg0, JsonConfig arg1) {
            throw new UnsupportedOperationException();
          }

          public Object processObjectValue(String arg0, Object arg1,
              JsonConfig arg2) {
            return new JSONRawString("Timeline.DateTime."
                + ((DateTime) arg1).toString());
          }

        });
    jsonConfig.registerJsonBeanProcessor(JsonConstructor.class,
        new JsonBeanProcessor() {

          public JSONObject processBean(Object arg0, JsonConfig arg1) {
            return (JSONObject) arg1.findJsonValueProcessor(
                JsonConstructor.class).processObjectValue(null,
                arg0, arg1);
          }

        });
    jsonConfig.registerJsonValueProcessor(JsonConstructor.class,
        new JsonValueProcessor() {
          public Object processArrayValue(Object arg0, JsonConfig arg1) {
            return processObjectValue(null, arg0, arg1);
          }

          public Object processObjectValue(String arg0, Object arg1,
              JsonConfig arg2) {
            JsonConstructor<?> constructor = (JsonConstructor<?>) arg1;
            return new JSONRawString(constructor.getName()
                + "("
                + WebUtils.toString(JSONObject.fromObject(
                    constructor.getObject(), arg2)) + ")");
          }

        });
    jsonConfig.registerJsonValueProcessor(RawString.class,
        new JsonValueProcessor() {
          public Object processArrayValue(Object arg0, JsonConfig arg1) {
            throw new UnsupportedOperationException();
          }

          public Object processObjectValue(String arg0, Object arg1,
              JsonConfig arg2) {
            return new JSONRawString(((RawString) arg1).toString());
          }

        });
    jsonConfig.registerJsonValueProcessor(RawString.class,
        new JsonValueProcessor() {
          public Object processArrayValue(Object arg0, JsonConfig arg1) {
            throw new UnsupportedOperationException();
          }

          public Object processObjectValue(String arg0, Object arg1,
              JsonConfig arg2) {
            return new JSONRawString(((RawString) arg1).toString());
          }

        });
    jsonConfig.registerJsonValueProcessor(Date.class,
        new JsonValueProcessor() {
          public Object processArrayValue(Object arg0, JsonConfig arg1) {
            throw new UnsupportedOperationException();
          }

          public Object processObjectValue(String arg0, Object arg1,
              JsonConfig arg2) {
            Date date = (Date) arg1;
            String dateString = new SimpleDateFormat("yyyy")
                .format(date);
            String retval = "Timeline.DateTime.parseGregorianDateTime(\""
                + dateString + "\")";
            return new JSONRawString(retval);
          }

        });
    jsonConfig.registerJsonValueProcessor(Date.class,
        new JsonValueProcessor() {
          public Object processArrayValue(Object arg0, JsonConfig arg1) {
            throw new UnsupportedOperationException();
          }

          public Object processObjectValue(String arg0, Object arg1,
View Full Code Here

  public JsonUtils()
  {
    jsonConfig = new JsonConfig();

    jsonConfig.registerJsonValueProcessor(DateTime.class, new JsonValueProcessor()
    {
      public Object processArrayValue(Object arg0, JsonConfig arg1)
      {
        throw new UnsupportedOperationException();
      }

      public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2)
      {
        return new JSONRawString("Timeline.DateTime." + ((DateTime)arg1).toString());
      }

    });
    jsonConfig.registerJsonBeanProcessor(JsonConstructor.class, new JsonBeanProcessor()
    {

      public JSONObject processBean(Object arg0, JsonConfig arg1)
      {
        return (JSONObject)arg1.findJsonValueProcessor(JsonConstructor.class)
          .processObjectValue(null, arg0, arg1);
      }

    });
    jsonConfig.registerJsonValueProcessor(JsonConstructor.class, new JsonValueProcessor()
    {
      public Object processArrayValue(Object arg0, JsonConfig arg1)
      {
        return processObjectValue(null, arg0, arg1);
      }

      public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2)
      {
        JsonConstructor<?> constructor = (JsonConstructor<?>)arg1;
        return new JSONRawString(constructor.getName() + "(" +
          WebUtils.toString(JSONObject.fromObject(constructor.getObject(), arg2)) + ")");
      }

    });
    jsonConfig.registerJsonValueProcessor(RawString.class, new JsonValueProcessor()
    {
      public Object processArrayValue(Object arg0, JsonConfig arg1)
      {
        throw new UnsupportedOperationException();
      }

      public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2)
      {
        return new JSONRawString(((RawString)arg1).toString());
      }

    });
    jsonConfig.registerJsonValueProcessor(RawString.class, new JsonValueProcessor()
    {
      public Object processArrayValue(Object arg0, JsonConfig arg1)
      {
        throw new UnsupportedOperationException();
      }

      public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2)
      {
        return new JSONRawString(((RawString)arg1).toString());
      }

    });
    jsonConfig.registerJsonValueProcessor(Date.class, new JsonValueProcessor()
    {
      public Object processArrayValue(Object arg0, JsonConfig arg1)
      {
        throw new UnsupportedOperationException();
      }

      public Object processObjectValue(String arg0, Object arg1, JsonConfig arg2)
      {
        Date date = (Date)arg1;
        String dateString = new SimpleDateFormat("yyyy").format(date);
        String retval = "Timeline.DateTime.parseGregorianDateTime(\"" + dateString + "\")";
        return new JSONRawString(retval);
      }

    });
    jsonConfig.registerJsonValueProcessor(Date.class, new JsonValueProcessor()
    {
      public Object processArrayValue(Object arg0, JsonConfig arg1)
      {
        throw new UnsupportedOperationException();
      }
View Full Code Here

         * Renders HTTP response.
         */
        public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException {
            // Date needs to be converted into iso-8601 date format.
            JsonConfig config = new JsonConfig();
            config.registerJsonValueProcessor(Date.class, new JsonValueProcessor() {

                public synchronized Object processArrayValue(Object value, JsonConfig jsonConfig) {
                    if (value != null){
                       DateFormat dateFormat = new SimpleDateFormat("MMM dd yyyy HH:mm:ss 'GMT'Z", Functions.getClientLocale());
                       return dateFormat.format(value);
View Full Code Here

TOP

Related Classes of net.sf.json.processors.JsonValueProcessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.