Package flexjson

Examples of flexjson.Path


public class MapTransformer extends AbstractTransformer {

    public void transform(Object object) {
        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));

                }

                path.pop();

            }
            getContext().writeCloseObject();
        } catch( Exception ex ) {
            throw new JSONException(String.format("%s: Error while trying to serialize.", path), ex);
View Full Code Here


{

  public void transform(Object object)
  {
    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));

      }

      path.pop();

    }
    getContext().writeCloseObject();
  }
View Full Code Here

public class DragomeClassTransformer extends AbstractTransformer
{
  public void transform(Object object)
  {
    JSONContext context= getContext();
    Path path= context.getPath();
    String name= ((Class) object).getName();
    name= name.replaceAll("_", ".");//TODO mejorar!!!
    TypeContext typeContext= context.writeOpenObject();

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

public class ObjectTransformer extends AbstractTransformer
{
  public void transform(Object object)
  {
    JSONContext context= getContext();
    Path path= context.getPath();
    ChainedSet visits= context.getVisits();
    try
    {
      if (!visits.contains(object))
      {
        context.setVisits(new ChainedSet(visits));
        context.getVisits().add(object);
        // traverse object
        BeanAnalyzer analyzer= BeanAnalyzer.analyze(resolveClass(object));
        TypeContext typeContext= context.writeOpenObject();

        context.writeName("@id");
        Integer objectId= getObjectId(object, context);
        context.getReferences().put(System.identityHashCode(object), objectId);
        context.write("" + objectId);

        context.writeComma();
        for (BeanProperty prop : analyzer.getProperties())
        {
          String name= prop.getName();
          path.enqueue(name);
          if (context.isIncluded(prop))
          {
            Object value= prop.getValue(object);
            //if (!context.getVisits().contains(value))
            {
              TransformerWrapper transformer= (TransformerWrapper) context.getTransformer(value);
              if ("class".equals(name)) //revisar esto!!!!
                transformer= new TransformerWrapper(new ClassTransformer());

              if (transformer == null)
                transformer= new TransformerWrapper(new NullTransformer());

              if ((transformer.getTransformer() instanceof ObjectTransformer) || !context.getVisits().contains(value))
              {
                if (!transformer.isInline())
                {
                  if (!typeContext.isFirst())
                    context.writeComma();
                  typeContext.setFirst(false);
                  context.writeName(name);
                }
                typeContext.setPropertyName(name);

                transformer.transform(value);
              }
            }
          }
          path.pop();
        }
        context.writeCloseObject();
        context.setVisits((ChainedSet) context.getVisits().getParent());

      }
View Full Code Here

TOP

Related Classes of flexjson.Path

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.