Package flexjson

Examples of flexjson.TypeContext


public class IterableTransformer extends AbstractTransformer {

    public void transform(Object object) {
        Iterable iterable = (Iterable) object;
        TypeContext typeContext = getContext().writeOpenArray();
        for (Object item : iterable) {
            if (!typeContext.isFirst()) getContext().writeComma();
            typeContext.increment();
            getContext().transform(item);
        }
        getContext().writeCloseArray();
    }
View Full Code Here


        JSONContext context = getContext();
        Path path = context.getPath();
        Map value = (Map) object;

        try {
            TypeContext typeContext = getContext().writeOpenObject();
            for (Object key : value.keySet()) {

                path.enqueue(key != null ? key.toString() : null);

                if (context.isIncluded(key != null ? key.toString() : null, value.get(key))) {

                    Transformer transformer = context.getTransformer(null, value.get(key));


                    if(!(transformer instanceof Inline) || !((Inline)transformer).isInline()) {
                        if (!typeContext.isFirst()) getContext().writeComma();
                        typeContext.increment();
                        if( key != null ) {
                            getContext().writeName(key.toString());
                        } else {
                            getContext().writeName(null);
                        }
                    }

                    if( key != null ) {
                        typeContext.setPropertyName(key.toString());
                    } else {
                        typeContext.setPropertyName(null);
                    }

                    transformer.transform(value.get(key));

                }
View Full Code Here

import java.lang.reflect.Array;

public class ArrayTransformer extends AbstractTransformer {

    public void transform(Object object) {
        TypeContext typeContext = getContext().writeOpenArray();
        int length = Array.getLength(object);
        for (int i = 0; i < length; ++i) {
            if (!typeContext.isFirst()) getContext().writeComma();
            typeContext.increment();
            getContext().transform(Array.get(object, i));
        }
        getContext().writeCloseArray();
    }
View Full Code Here

            return;
        }

        boolean setContext = false;

        TypeContext typeContext = getContext().peekTypeContext();
        String propertyName = typeContext != null ? typeContext.getPropertyName() : "";
        if(prefix.trim().equals("")) prefix = propertyName;

        if (typeContext == null || typeContext.getBasicType() != BasicType.OBJECT) {
            typeContext = getContext().writeOpenObject();
            setContext = true;
        }

        Date date = (Date) o;
        Calendar c = Calendar.getInstance();
        c.setTime(date);

        if (!typeContext.isFirst()) getContext().writeComma();
        typeContext.increment();
        getContext().writeName(fieldName("Month"));
        getContext().transform(c.get(Calendar.MONTH));

        getContext().writeComma();
        getContext().writeName(fieldName("Day"));
View Full Code Here

        if( object == null ) {
            getContext().write("null");
            return;
        }
        String[] stringArr = (String[]) object;
        TypeContext typeContext = getContext().writeOpenArray();
        for (String item : stringArr) {
            if (!typeContext.isFirst()) getContext().writeComma();
            typeContext.increment();
            getContext().transform(item.toUpperCase());
        }
        getContext().writeCloseArray();

    }
View Full Code Here

  {
    int identityHashCode= System.identityHashCode(object);

    JSONContext context= getContext();

    TypeContext typeContext= context.writeOpenObject();
    context.writeName("@id");
    context.write("" + identityHashCode);

    context.writeComma();
    context.writeName("class");
View Full Code Here

{

  public void transform(Object object)
  {
    Iterable iterable= (Iterable) object;
    TypeContext typeContext= getContext().writeOpenArray();
    for (Object item : iterable)
    {
      if (!typeContext.isFirst())
        getContext().writeComma();
      typeContext.setFirst(false);
      getContext().transform(item);
    }
    getContext().writeCloseArray();
  }
View Full Code Here

  {
    JSONContext context= getContext();
    Path path= context.getPath();
    Map value= (Map) object;

    TypeContext typeContext= getContext().writeOpenObject();
    for (Object key : value.keySet())
    {

      path.enqueue(key != null ? key.toString() : null);

      if (context.isIncluded(key != null ? key.toString() : null, value.get(key)))
      {

        TransformerWrapper transformer= (TransformerWrapper) context.getTransformer(value.get(key));

        if (!transformer.isInline())
        {
          if (!typeContext.isFirst())
            getContext().writeComma();
          typeContext.setFirst(false);
          if (key != null)
          {
            getContext().writeName(key.toString());
          }
          else
          {
            getContext().writeName(null);
          }
        }

        if (key != null)
        {
          typeContext.setPropertyName(key.toString());
        }
        else
        {
          typeContext.setPropertyName(null);
        }

        transformer.transform(value.get(key));

      }
View Full Code Here

  {
    JSONContext context= getContext();
    Element element= (Element) object;
    String id= System.identityHashCode(element) + "";
    element.setAttribute("data-debug-id", id);
    TypeContext typeContext= context.writeOpenObject();

    context.writeName("id");
    context.writeQuoted(id);
    context.writeComma();
    context.writeName("class");
View Full Code Here

  {
    JSONContext context= getContext();
    Path path= context.getPath();
    String name= ((Class) object).getName();
    name= name.replaceAll("_", ".");//TODO mejorar!!!
    TypeContext typeContext= context.writeOpenObject();

    context.writeName("name");
    context.writeQuoted(name);
    context.writeComma();
    context.writeName("class");
View Full Code Here

TOP

Related Classes of flexjson.TypeContext

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.