Package net.arnx.jsonic.util

Examples of net.arnx.jsonic.util.PropertyInfo


    out.append('{');
    int count = 0;
    final int length = props.size();
    for (int p = 0; p < length; p++) {
      PropertyInfo prop = props.get(p);
      Object value = null;
      Exception cause = null;

      try {
        value = prop.get(o);
        if (value == src || (context.isSuppressNull() && value == null))
          continue;

        if (count != 0) out.append(',');
        if (context.isPrettyPrint()) {
          out.append('\n');
          for (int j = 0; j < context.getLevel() + 1; j++)
            out.append('\t');
        }
      } catch (Exception e) {
        cause = e;
      }
     
      StringFormatter.serialize(context, prop.getName(), out);
      out.append(':');
      if (context.isPrettyPrint()) out.append(' ');
      context.enter(prop.getName(), prop.getReadAnnotation(JSONHint.class));
      if (cause != null) throw cause;
     
      value = json.preformatInternal(context, value);
      json.formatInternal(context, value, out);
      context.exit();
View Full Code Here


                if (!hint.name().isEmpty()) {
                  mName = hint.name();
                } else if (getPropertyCaseStyle() != null) {
                  mName = getPropertyCaseStyle().to(mName);
                }
                props.add(new PropertyInfo(prop.getBeanClass(), mName,
                    null, prop.getReadMethod(), prop.getWriteMethod(), prop.isStatic(), hint.ordinal()));
              }
            } else if (getPropertyCaseStyle() != null) {
              mName = getPropertyCaseStyle().to(prop.getName());
              props.add(new PropertyInfo(prop.getBeanClass(), mName,
                  prop.getField(), prop.getReadMethod(), prop.getWriteMethod(), prop.isStatic(), prop.getOrdinal()));
            } else {
              mName = prop.getName();
              props.add(prop);
            }
          }
         
          if (prop.getField() != null && !ignore(this, c, prop.getField())) {
            JSONHint hint = prop.getField().getAnnotation(JSONHint.class);
            if (hint != null) {
              String name = prop.getName();
              if (!hint.name().isEmpty()) {
                name = hint.name();
              } else if (getPropertyCaseStyle() != null) {
                name = getPropertyCaseStyle().to(name);
              }
              if (!name.equals(mName) && !hint.ignore()) {
                props.add(new PropertyInfo(prop.getBeanClass(), name,
                    prop.getField(), null, null, prop.isStatic(), hint.ordinal()));
              }
            } else if (mName != null) {
              String name = prop.getName();
              if (getPropertyCaseStyle() != null) {
                name = getPropertyCaseStyle().to(name);
              }
              if (!name.equals(mName)) {
                props.add(new PropertyInfo(prop.getBeanClass(), name,
                    prop.getField(), null, null, prop.isStatic(), prop.getOrdinal()));
              }
            } else if (getPropertyCaseStyle() != null) {
              props.add(new PropertyInfo(prop.getBeanClass(), getPropertyCaseStyle().to(prop.getName()),
                  prop.getField(), prop.getReadMethod(), prop.getWriteMethod(), prop.isStatic(), prop.getOrdinal()));
            } else {
              props.add(prop);
            }
          }
View Full Code Here

            order = hint.ordinal();
          }
         
          if (name != null) {
            if (prop.getWriteMethod() != null && prop.getField() != null && !Modifier.isFinal(prop.getField().getModifiers())) {
              props.put(name, new PropertyInfo(prop.getBeanClass(), name,
                  null, prop.getReadMethod(), prop.getWriteMethod(), prop.isStatic(), order));
              prop = new PropertyInfo(prop.getBeanClass(), prop.getName(),
                  prop.getField(), null, null, prop.isStatic(), order);
            } else {
              props.put(name, new PropertyInfo(prop.getBeanClass(), name,
                  prop.getField(), prop.getReadMethod(), prop.getWriteMethod(), prop.isStatic(), order));
              continue;
            }
          } else if (order >= 0) {
            prop = new PropertyInfo(prop.getBeanClass(), prop.getName(),
                prop.getField(), prop.getReadMethod(), prop.getWriteMethod(), prop.isStatic(), order);
          }
       
          props.put(prop.getName(), prop);
          if (getPropertyCaseStyle() != null) {
View Full Code Here

    if (value instanceof Map<?, ?>) {
      Object o = json.create(context, c);
      if (o == null) return null;
      for (Map.Entry<?, ?> entry : ((Map<?, ?>)value).entrySet()) {
        String name = entry.getKey().toString();
        PropertyInfo target = props.get(name);
        if (target == null) target = props.get(toLowerCamel(context, name));
        if (target == null) continue;
       
        context.enter(name, target.getWriteAnnotation(JSONHint.class));
        Class<?> cls = target.getWriteType();
        Type gtype = target.getWriteGenericType();
        if (gtype instanceof TypeVariable<?> && t instanceof ParameterizedType) {
          gtype = resolveTypeVariable((TypeVariable<?>)gtype, (ParameterizedType)t);
          cls = ClassUtil.getRawType(gtype);
        }
        target.set(o, json.postparse(context, entry.getValue(), cls, gtype));
        context.exit();
      }
      return o;
    } else if (value instanceof List<?>) {
      throw new UnsupportedOperationException("Cannot convert " + value.getClass() + " to " + t);
    } else {
      JSONHint hint = context.getHint();
      if (hint != null && hint.anonym().length() > 0) {
        PropertyInfo target = props.get(hint.anonym());
        if (target == null) return null;
        Object o = json.create(context, c);
        if (o == null) return null;
        context.enter(hint.anonym(), target.getWriteAnnotation(JSONHint.class));
        Class<?> cls = target.getWriteType();
        Type gtype = target.getWriteGenericType();
        if (gtype instanceof TypeVariable<?> && t instanceof ParameterizedType) {
          gtype = resolveTypeVariable((TypeVariable<?>)gtype, (ParameterizedType)t);
          cls = ClassUtil.getRawType(gtype);
        }
        target.set(o, json.postparse(context, value, cls, gtype));
        context.exit();
        return o;
      } else {
        throw new UnsupportedOperationException("Cannot convert " + value.getClass() + " to " + t);
      }
View Full Code Here

TOP

Related Classes of net.arnx.jsonic.util.PropertyInfo

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.