Package org.nutz.json

Examples of org.nutz.json.JsonField


  private Injecting injecting;

  private Ejecting ejecting;

  public static JsonEntityField eval(Mirror<?> mirror, Field fld) {
    JsonField jf = fld.getAnnotation(JsonField.class);
    if (null != jf && jf.ignore())
      return null;

    JsonEntityField jef = new JsonEntityField();
    jef.injecting = mirror.getInjecting(fld.getName());
    jef.ejecting = mirror.getEjecting(fld.getName());
    jef.genericType = fld.getGenericType();

    if (null != jf && !Strings.isBlank(jf.value()))
      jef.name = jf.value();
    else
      jef.name = fld.getName();

    return jef;
  }
View Full Code Here


        // XXX 有用户就是_开头的字段也要啊! by wendal
      //if (fld.getName().startsWith("_") || fld.getName().startsWith("$"))
      if (fld.getName().startsWith("$") && fld.getAnnotation(JsonField.class) == null)
        return null;
     
        JsonField jf = fld.getAnnotation(JsonField.class);
        if (null != jf && jf.ignore())
            return null;

        JsonEntityField jef = new JsonEntityField();
        jef.genericType = Lang.getFieldType(mirror, fld);
        jef.name = Strings.sBlank(null == jf ? null : jf.value(), fld.getName());
        jef.ejecting = mirror.getEjecting(fld.getName());
        jef.injecting = mirror.getInjecting(fld.getName());

        return jef;
    }
View Full Code Here

            }
            fields.add(ef);
            fieldMap.put(ef.getName(), ef);
        }
        for (Method m : mirror.getMethods()) {
            final JsonField jf = m.getAnnotation(JsonField.class);
            // 忽略方法
            if (null == jf || jf.ignore())
                continue;

            // 如果有,尝试作新的 Entity
            final Method method = m;
            Callback<Method> whenError = new Callback<Method>() {
                // 给定方法即不是 getter 也不是 setter,靠!玩我!
                public void invoke(Method m) {
                    throw Lang.makeThrow(JsonException.class,
                                         "JsonField '%s' should be getter/setter pair!",
                                         m);
                }
            };
            Callback3<String, Method, Method> whenOk = new Callback3<String, Method, Method>() {
                public void invoke(String name, Method getter, Method setter) {
                    // 防止错误
                    if (null == getter || null == setter || Strings.isBlank(name)) {
                        throw Lang.makeThrow(JsonException.class,
                                             "JsonField '%s' should be getter/setter pair!",
                                             method);
                    }
                    // 加入字段表
                    JsonEntityField ef = JsonEntityField.eval(Strings.sBlank(jf.value(), name),
                                                              getter,
                                                              setter);
                    fields.add(ef);
                    fieldMap.put(ef.getName(), ef);
                }
View Full Code Here

        // if (fld.getName().startsWith("_") || fld.getName().startsWith("$"))
        if (fld.getName().startsWith("$")
            && fld.getAnnotation(JsonField.class) == null)
            return null;

        JsonField jf = fld.getAnnotation(JsonField.class);

        JsonEntityField jef = new JsonEntityField();
        jef.genericType = Lang.getFieldType(mirror, fld);
        jef.name = Strings.sBlank(null == jf ? null : jf.value(), fld.getName());
        jef.ejecting = mirror.getEjecting(fld.getName());
        jef.injecting = mirror.getInjecting(fld.getName());

        // 瞬时变量和明确声明忽略的,变 ignore
        if (Modifier.isTransient(fld.getModifiers())
            || (null != jf && jf.ignore())) {
            jef.setIgnore(true);
        }


        // 判断字段是否被强制输出为字符串
        if (null != jf) {
            jef.setForceString(jf.forceString());
        }
       
        JsonIgnore jsonIgnore = fld.getAnnotation(JsonIgnore.class);
        if (jsonIgnore != null) {
            Mirror<?> fldMirror = Mirror.me(fld.getType());
View Full Code Here

TOP

Related Classes of org.nutz.json.JsonField

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.