Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.core.json;
  
Extension of com.fasterxml.jackson.core.JsonStreamContext, which implements core methods needed, and also exposes more complete API to generator implementation classes.
  
 public class JsonWriteContext
     extends JsonStreamContext
 {
     // // // Return values for writeValue()
 
     public final static int STATUS_OK_AS_IS = 0;
     public final static int STATUS_OK_AFTER_COMMA = 1;
     public final static int STATUS_OK_AFTER_COLON = 2;
     public final static int STATUS_OK_AFTER_SPACE = 3; // in root context
     public final static int STATUS_EXPECT_VALUE = 4;
     public final static int STATUS_EXPECT_NAME = 5;
 
     protected final JsonWriteContext _parent;

    
Name of the field of which value is to be parsed; only used for OBJECT contexts
 
     protected String _currentName;
     
     /*
     /**********************************************************
     /* Simple instance reuse slots; speed up things
     /* a bit (10-15%) for docs with lots of small
     /* arrays/objects
     /**********************************************************
      */
 
     protected JsonWriteContext _child = null;
 
     /*
     /**********************************************************
     /* Life-cycle
     /**********************************************************
      */
 
     protected JsonWriteContext(int typeJsonWriteContext parent)
     {
         super();
          = type;
          = parent;
          = -1;
     }
     
     // // // Factory methods
 
     public static JsonWriteContext createRootContext()
     {
         return new JsonWriteContext(null);
     }
 
     private JsonWriteContext reset(int type) {
          = type;
          = -1;
          = null;
         return this;
     }
     
     public final JsonWriteContext createChildArrayContext()
     {
         JsonWriteContext ctxt = ;
         if (ctxt == null) {
              = ctxt = new JsonWriteContext(this);
             return ctxt;
         }
         return ctxt.reset();
     }
 
     public final JsonWriteContext createChildObjectContext()
     {
         JsonWriteContext ctxt = ;
         if (ctxt == null) {
              = ctxt = new JsonWriteContext(this);
             return ctxt;
         }
         return ctxt.reset();
     }
 
     // // // Shared API
 
     @Override
     public final JsonWriteContext getParent() { return ; }
 
     @Override
     public final String getCurrentName() { return ; }
     
     // // // API sub-classes are to implement
 
    
Method that writer is to call before it writes a field name.

Returns:
Index of the field entry (0-based)
    public final int writeFieldName(String name)
    {
        if ( == ) {
            if ( != null) { // just wrote a name...
                return ;
            }
             = name;
            return ( < 0) ?  : ;
        }
        return ;
    }
    
    public final int writeValue()
    {
        // Most likely, object:
        if ( == ) {
            if ( == null) {
                return ;
            }
             = null;
            ++;
            return ;
        }
        // Ok, array?
        if ( == ) {
            int ix = ;
            ++;
            return (ix < 0) ?  : ;
        }
        
        // Nope, root context
        // No commas within root context, but need space
        ++;
        return ( == 0) ?  : ;
    }
    // // // Internally used abstract methods
    protected final void appendDesc(StringBuilder sb)
    {
        if ( == ) {
            sb.append('{');
            if ( != null) {
                sb.append('"');
                // !!! TODO: Name chars should be escaped?
                sb.append();
                sb.append('"');
            } else {
                sb.append('?');
            }
            sb.append('}');
        } else if ( == ) {
            sb.append('[');
            sb.append(getCurrentIndex());
            sb.append(']');
        } else {
            // nah, ROOT:
            sb.append("/");
        }
    }
    // // // Overridden standard methods

    
Overridden to provide developer writeable "JsonPath" representation of the context.
    @Override
    public final String toString()
    {
        StringBuilder sb = new StringBuilder(64);
        appendDesc(sb);
        return sb.toString();
    }
New to GrepCode? Check out our FAQ X